c# - MVC5 JSON parsing -


i have json 3rd party system (so can't change json). trying parse list of methoditems, items collection null. using built-in mvc 5 json deserializer in controller action. missing.

{ "method": {         "name": "getitems",         "items": {             "item 1": {                 "name": "myitem",                 "value": "toothbrush"             },             "item 2": {                 "name": "my item 2",                 "value": "razor"             }         }  } 

c# objects here

public class requestroot {     public method method { get; set; } }  public class method {     public string name { get; set; }     public methoditem[] items { get; set; } }  public class methoditem {     public string name { get; set; }     public string value { get; set; } } 

items should treat dictionary, try this:

public class method  {      public string name { get; set; }     public dictionary<string,methoditem> items { get; set; }  }  public class methoditem  {      public string name { get; set; }     public string value { get; set; }  } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -