通过索引访问json对象数据

我有以下数组结构的 json 对象。我正在尝试从对象数组中检索某些元素


{

"data": [

{

"_id": "5b62dc6ebef986403db8aafd",

"name": "smitha vijaya",

"designation": "account management",

"projects": {

"project1": "description1",

"project2": "description2"

},

"age": "27"

},

{

"_id": "5b62dd17bef986403db8ab90",

"name": "JIKKU VARGHESE",

"designation": "SUPERVISING OPERATIONS MANAGER",

"projects": {

"project1": "description1",

"project2": "description2"

},

"age": "27"

},

{

"_id": "5b62dd76bef986403db8abe3",

"name": "SUJEETH  NAIR",

"designation": "MENA AMS",

"projects": {

"project1": "description1",

"project2": "description2"

},

"age": "30"

},

{

"_id": "5b62ddb1bef986403db8ac13",

"name": "GIRISH   KN",

"designation": "MENA  AMS",

"projects": {

"project1": "description1",

"project2": "description2"

},

"age": "27"

}

]

}

我正在使用以下 c# 代码来提取 ist 名称(smitha)


JsonData jsonvale = JsonMapper.ToObject( jsonString);

         Name = jsonvale["data"][0]["name"].ToString();

print (name);

我如何访问其他元素,如名称 jikku 等?


HUWWW
浏览 287回答 3
3回答

开心每一天1111

您可以使用 for 循环进行迭代:for(int i = 0; i < jsonvale.length; i++) {&nbsp; &nbsp; JsonData jsonvale = JsonMapper.ToObject(jsonString);&nbsp; &nbsp; Name = jsonvale["data"][i]["name"].ToString();&nbsp; &nbsp; print(name);}

慕容森

只需在 List() 中反序列化这个 json,然后你就可以访问这个列表中的所有数据而无需循环,当你不再需要这个列表时,你可以销毁它。请参阅此示例https://github.com/IonCojucovschi/JsonDeserializeGenericForm

小唯快跑啊

你可以像下面这样遍历你的 json 数组:JsonData jsonvale = JsonMapper.ToObject( jsonString);for (var i=0; i<jsonvale.length; i++){&nbsp; &nbsp; print(jsonvale["data"][i]["name"].ToString());}
打开App,查看更多内容
随时随地看视频慕课网APP