我需要从json输出中获取一个项目,但json内容并不总是一致的。
例如,如果我想获取“name”的值,它将是['result']['attributes'][0]['name'];
但是如果json以第二个示例传递,则应为['result']['attributes'][1]['name'];
{"result":{
"attributes":[
{"user":"newb","name":"mike"},
{"state":"california","city":"los angeles"}
]
}}
{"result":{
"attributes":[
{"state":"california","city":"los angeles"},
{"user":"newb","name":"mike"}
]
}}
如果不知道数组中的索引,我该如何获取“name”值?
{"result":{"attributes":{"user":"newb","name":"mike","state":"california","city":"los angeles"}}}
- Shaggy Frog