我有以下数组结构的 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 等?
3 回答
开心每一天1111
TA贡献1836条经验 获得超13个赞
您可以使用 for 循环进行迭代:
for(int i = 0; i < jsonvale.length; i++) {
JsonData jsonvale = JsonMapper.ToObject(jsonString);
Name = jsonvale["data"][i]["name"].ToString();
print(name);
}
慕容森
TA贡献1853条经验 获得超18个赞
只需在 List() 中反序列化这个 json,然后你就可以访问这个列表中的所有数据而无需循环,当你不再需要这个列表时,你可以销毁它。请参阅此示例https://github.com/IonCojucovschi/JsonDeserializeGenericForm
小唯快跑啊
TA贡献1863条经验 获得超2个赞
你可以像下面这样遍历你的 json 数组:
JsonData jsonvale = JsonMapper.ToObject( jsonString);
for (var i=0; i<jsonvale.length; i++){
print(jsonvale["data"][i]["name"].ToString());
}
- 3 回答
- 0 关注
- 277 浏览
添加回答
举报
0/150
提交
取消