How to parse nested JSON objects with JSON framework and Objective-C/iPhone/Xcode?

前端 未结 4 1911
旧时难觅i
旧时难觅i 2020-12-16 05:48

I\'m writing an iPhone native app using the JSON framework.

My app is accessing web services using JSON. The JSON data we send has nested objects, below is an exampl

4条回答
  •  孤城傲影
    2020-12-16 06:42

    It is hard to tell without some more details (e.g. the JSON parsing code that you are using), but two things strike me as possible:

    1. you are not querying with a full path. In the case above, you'd need to first get the enclosing model, the json response, and only then ask the json response dictionary for the authenticationFlag value:

      [[[jsonDict objectForKey:@"model"] objectForKey:@"JSONRESPONSE"] objectForKey:@"authenticationFlag"]

    2. perhaps you're using c-strings ("") rather than NSStrings (@"") as keys (although this would likely crash nastily or just not compile). The key should be something than can be cast to id.

    While possible, both are probably false, so please include more detail.

提交回复
热议问题