解析嵌套的JSON条目 [英] Parsing nested JSON entries
本文介绍了解析嵌套的JSON条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我只解析了初始数组上的JSON,但不确定如何进行.
So far i've only ever parsed JSON that was on an initial array but am unsure how to proceed.
这是我的JSON:
{
"SongDeviceID": [
{
"SID": "714",
"SDID": "1079287588763212246"
},
{
"SID": "715",
"SDID": "1079287588763212221"
},
{
"SID": "716",
"SDID": "1079287588763212230"
}
]
}
这是我到目前为止在代码中所拥有的:
And here is what I have so far in my code:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonResponse options: NSJSONReadingMutableContainers error: &e];
NSArray * responseArr = [NSArray arrayWithObject:jsonResponse];
for (NSDictionary *dict in responseArr)
我认为我走错路了,因为我过去只拥有一层深层的JSON响应,有人可以帮我吗?
I think im going about this the wrong way because im used to having only one layer deep JSON responses, can somebody help me out?
推荐答案
您很亲密.您需要:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonResponse options: NSJSONReadingMutableContainers error: &e];
NSArray * responseArr = jsonArray[@"SongDeviceID"];
for (NSDictionary *dict in responseArr) {
// dict has two keys - SID and SDID
}
这篇关于解析嵌套的JSON条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文