使用 JSONKit 处理 WordPress JSON 响应
我使用 JSONKit 解析来自 WordPress 博客的数据。
NSData *wp_json = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSDictionary *posts = [wp_json objectFromJSONData]
收到的数据是 JSON,所以当我这样做时,它工作得很好
NSLog(@"%@",[posts objectForKey:@"count"]);
,然后我想访问帖子,但有问题帖子是一个子 json(如果我可以这么说)并且有 X 个帖子,所以我可以获得一个大字符串所有代码,我不知道如何仅获取第一篇文章的 id,然后获取第二篇文章的 id。
我怎样才能做到这一点?
JSON 响应看起来像这样,因此更容易理解。
I use JSONKit to parse data from a wordpress blog.
NSData *wp_json = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSDictionary *posts = [wp_json objectFromJSONData]
the data received is JSON so when I do this it works perfectly
NSLog(@"%@",[posts objectForKey:@"count"]);
then I want to access the posts and there is the problem posts is a sub json (if I can say that) and there is X posts so I can get a big string with all the code and I don't know how to get only the id for the first post then the id for the 2nd post.
How can I do that?
The JSON response looks like this so it will be easier to understand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您返回的原始 JSON 只是一个字典,而帖子是该字典中保存的数组。
该数组中的每个元素都是另一个字典,但这次代表一篇文章。您可以迭代它,对每个帖子执行您想要的操作,如下所示:
Your raw JSON you get back is simply a dictionary, and the posts are an array held in that dictionary.
Each element in that array is yet another dictionary, but this time representing a post. You can iterate through it to do what you want with each post like so: