简体   繁体   English

解析嵌套的JSON条目

[英]Parsing nested JSON entries

So far i've only ever parsed JSON that was on an initial array but am unsure how to proceed. 到目前为止,我只解析了初始数组上的JSON,但不确定如何进行。

Here is my JSON: 这是我的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)

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? 我认为这是错误的做法,因为我过去只拥有一层深层的JSON响应,有人可以帮助我吗?

You are close. 你近了 You need: 你需要:

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM