Getting values from a nested array in JSON using Script.Serialization in C# -


i trying values nested json data

my json data looks this:

{         \"user\": \"wer8943t5342t89\",         \"action\":\"user\",         \"data\": [             {             "name": "john",             "username": "johnd",             "role": "admin",              "group": [                 {                 "id":"group1",                 "id":"group2",                 "id":"group3"                 }]             },             {             "name": "jane",             "username": "janed",             "role": "admin",             "group": [                 {                 "id":"group1",                 "id":"group2"                 }]             }     ]} 

and c# code this:

javascriptserializer js = new javascriptserializer(); var d = js.deserialize<dynamic>(json);  // root data string root_user = d["user"]; string root_action = d["action"];  // first level data dynamic[] _data = d["data"]; var _data_length = _data.length; (int = 0; < _data_length; i++) {     _data_name += _data[i]["name"]; }  //second level data dynamic[] _group = d["data"][0]["group"]; var _group_length = _group.length; var _group_id = _group[0]["id"]; 

whatever seems last value (group3) , _group.length 1 regardless of values in json data.

it not option use newton or similar, has done script serialization reasons not mentioned here.

hope few pointers


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -