Reputation: 1037
I am using javascriptserializer to deserialize json data. I am stuck on how to parse this data and assign the value to a variable.
json:
{
"data1": {
"EntityList": "Attribute",
"KeyName": "AkeyName",
"Value": "Avalue"
},
"data2": {
"Id": "jsdksjkjdiejkwp12193jdmsldm",
"Status": "OK"
}
}
I need to assign the values of EntityList, KeyName in data1 to a variable. I read this json string into a variable data
c#:
var data = "json string"; //variable with json string
JavaScriptSerializer jss = new JavaScriptSerializer();
dynamic drecord = jss.Deserialize<dynamic>(data);
I am trying to parse this nested json into 2 variables EntityList & KeyName.
Upvotes: 0
Views: 418
Reputation: 1026
If I understood you correct so it must be smth like this:
JavaScriptSerializer jss = new JavaScriptSerializer();
dynamic record = jss.Deserialize<dynamic>(data);
var data1 = record["data1"];
var entityList = data1["EntityList"];
var keyName = data1["KeyName"];
Upvotes: 1