Part of my Json structre is dynacmic array and i want to read it using Json.Net . The json structre is
{
"objects": [{
"id": "521daea47288c7794c88c923",
"name": "Rass",
"email": "[email protected]",
"username": "ras",
"books": [],
"devices": [],
"preferences": [
{
"name": "key1",
"value": [
{
"id": "val1Id",
"params": [
{
"name": "set1key",
"value": 0
},
{
"name": "set1key2",
"value": 0
},
{
"name": "set1key3",
"value": 0.5
}
]
},
{
"id": "val2Id",
"params": [
{
"name": "set2key",
"value": 0
},
{
"name": "set2key2",
"value": 0
},
{
"name": "set2key3",
"value": 0.5
}
]
}
]
},
{
"name": "language",
"value": "en_US"
},
{
"name": "page_zoom",
"value": 1
}
],
"created": "2013-08-28T08:02:44.000Z"
}],
"meta": {
"total_count": 1,
"offset": 0,
"limit": 1000
}
}
How can i access the set of preferences in my c# code . I gets the preference tag from json using the below code
var jObject = JObject.Parse(jsonString);
JObject obj = (JObject)jObject["objects"][0]["preferences"][0];
string pref = "";
foreach (var pref_item in obj)
{
string key = pref_item.Key;
//Here i want to check the Value is of type array, then get each item from Array.
//If its not an array simply read the value
}
Now i want to navigate to each preference items , store the name and value properties. If Value is array i want to access each items in that array . How can i do it?
[0]at the end it would be all the preferences). So what's going wrong with the code you've got?JArray, but you can ask for any element within thatJArray. So what exactly are you trying to do with the preferences, what code have you tried, and what went wrong? It's hard to help you without concrete requirements.