I've json table like this, how I can attempd to specific data?
var json_str={ "table1":[
{"name1":"data1"},
{"name2":"data2"},
{"name3":"data3"}
],
"table2":[
{"name1":"data1"},
{"name2":"data2"},
{"name3":"data3"}
]
}
dynamic stuff = JsonConvert.DeserializeObject(json_string);
//I'd like attempt to data like this(for example)
var abc=stuff.table1["name1"];
this is obviously wrong, but is there any method to call the contents of the json table by name?
SOLVED: I changed my json to
var json_str={ "table1":{
"name1":"data1",
"name2":"data2",
"name3":"data3"
},
"table2":{
"name1":"data1",
"name2":"data2",
"name3":"data3"
}
}
var abc=JsonConvert.DeserializeObject<Form1.RootObject>(json_str);
and now I have attempt (for example) by:
abc.table1.name2;
Many thanks to xdtTransform and everyone for the hints.
>(json_string) I get an error: "Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Test_timer.Form1+RootObject]' because the type requires a JSON array (e.g. [1,2,3])"
– yaceq Oct 21 '19 at 10:28