访问由 JSON 框架 iPhone 生成的嵌套数组和字典
我正在使用 Google API 返回一些 JSON,我已使用 JSON 框架(Stig B - Google 代码)将其转换为 Objective C 类型。
我现在有这样的结构:
responseData
results
[0]
title = "Stack Overflow"
cursor
如何访问嵌套数组 results
来获取 title
值(我猜是字典)?
我已经尝试过,但没有成功:
for (NSString *key in [jsonObjects objectForKey:@"responseData"]) {
NSLog(@"%@",key);
for (NSString *element in [key valueForKey:@"results"]) {
NSLog(@"%@",element);
}
}
外部循环将打印出数组 results
和 cursor
的名称,这样就可以工作,但对于内部循环,我得到一个 <代码>不符合键值编码错误。
谢谢
I'm using a Google API to return some JSON, which i have converted to their Objective C types using the JSON-framework (Stig B - Google Code).
I now have structures like this:
responseData
results
[0]
title = "Stack Overflow"
cursor
How can i access the nested array results
to get at the title
value (dictionary i'm guessing)?
I have tried this but no success:
for (NSString *key in [jsonObjects objectForKey:@"responseData"]) {
NSLog(@"%@",key);
for (NSString *element in [key valueForKey:@"results"]) {
NSLog(@"%@",element);
}
}
The outer loop will print out the names of the arrays results
and cursor
so that works, but for the inner loop, I get a not key value coding compliant
error.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 NSLog([jsonObjects description]) 来查看字典的内容和结构。
要浏览到“结果”数组及其内容,您可以使用以下(或类似)代码:
You can use
NSLog([jsonObjects description])
to see the contents and structure of your dictionary.To browse to your "results" array and its contents you can use the following (or similar) code: