到目前为止,我只解析过初始数组中的 JSON,但不确定如何继续。
这是我的 JSON:
{
"SongDeviceID": [
{
"SID": "714",
"SDID": "1079287588763212246"
},
{
"SID": "715",
"SDID": "1079287588763212221"
},
{
"SID": "716",
"SDID": "1079287588763212230"
}
]
}
这是我目前的代码:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonResponse options: NSJSONReadingMutableContainers error: &e];
NSArray * responseArr = [NSArray arrayWithObject:jsonResponse];
for (NSDictionary *dict in responseArr)
我认为我以错误的方式解决这个问题,因为我习惯于只有一层深度 JSON 响应,有人可以帮我吗?
最佳答案
你很接近。你需要:
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
}
关于ios - 解析嵌套的 JSON 条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18415329/