Using json.net from string to datatable in C# -


hopefully can me example, because i'm new in json: webservice receive json string. understand created datatable. how manage in c# deserialize dataset? maybe has me.

{   "datatojohnson": {     "0": {       "maat_id": "1",       "maat": "11"     },     "1": {       "maat_id": "2",       "maat": "11+"     },     "2": {       "maat_id": "3",       "maat": "12+"     },     "3": {       "maat_id": "4",       "maat": "12/13"     }   } } 

thanks!

raymond

you define model represent json data:

public class data {     public int maat_id { get; set; }     public string maat { get; set; } }  public class mymodel {     public dictionary<int, data> datatojohnson { get; set; } } 

and use json.net deserialize string model

var json =  @"{   ""datatojohnson"": {     ""0"": {       ""maat_id"": ""1"",       ""maat"": ""11""     },     ""1"": {       ""maat_id"": ""2"",       ""maat"": ""11+""     },     ""2"": {       ""maat_id"": ""3"",       ""maat"": ""12+""     },     ""3"": {       ""maat_id"": ""4"",       ""maat"": ""12/13""     }   } }"; mymodel model = jsonconvert.deserializeobject<mymodel>(json); foreach (var item in model.datatojohnson) {     console.writeline(         "id: {0}, maat_id: {1}, maat: {2}",          item.key, item.value.maat_id, item.value.maat     ); } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -