如何使用 Objective C 获取并解析 JSON?
是否可以使用 Objective C 获取并解析 JSON,然后在 iphone/pad 的 cocoa 框架内操作它?我特别希望为几个公共 API 执行此操作。
Is it possible to get and parse JSON using objective C, then manipulate it within the cocoa framework for the iphone/pad? I'm specifically looking to do this for a couple of public APIs out there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请参阅此处:如何在 iPhone 中进行 json 解析
基本上,您应该查看 TouchJSON 库(使用 CJSONDeserializer 和 CJSONSerializer)。
See here: how to do json parsing in iphone
Basically, you should look into the TouchJSON library (with CJSONDeserializer and CJSONSerializer).
在之前的一些项目中使用了 Json-framework,效果非常好。
编辑:我读你的帖子有点太快了。我之前在 Mac 应用程序上使用过它,但不针对 iphone/ipad。我认为它应该有效,但没有背景。也许其他人可以确认?
Used Json-framework on some previous projects, worked really well.
EDIT: I read your post a bit too fast. I've used it on a Mac app before but not targeting the iphone/ipad. I think it should work but have no background to it. Maybe someone else can confirm?
如果您使用专门用于此任务的许多现有开源项目之一,这不仅是可能的,而且非常简单。我建议尝试 yajl-objc,它提供了流解析器,但是 json-framework 也是一个很好的框架。他们非常相似。
It's not only possible, it's dirt simple if you use one of the many existing open source projects dedicated to this task. I recommend trying yajl-objc, which offers a streaming parser, but json-framework is a good one too. They're very similar.
我会远离 TouchJSON,因为它在字符串中的特殊字符(换行符)给我带来了麻烦。
不过,我会加入推荐 json-framework 的合唱团。自从我从 TouchJSON 切换到 TouchJSON 以来,一切都运行顺利。
关于如何将 API 集成到您的项目中,它们的包含和使用同样简单。
作为旁注,我现在刚刚测试 JSONKit,因为它应该比两者都快得多TouchJSON 和 json 框架。但是,我还不能保证它的稳定性。不过它的评价还是不错的。
I'd stay away from TouchJSON, since it gave me trouble a while back with special characters (line breaks) in strings.
However, I'll join the choir recommending json-framework. Since I switched to that from TouchJSON everything's been running smoothly.
Regarding how to integrate the API in your project, they're equally simple to include and use.
As a side note, I'm just now testing out JSONKit, since it's supposed to be much faster than both TouchJSON and json-framework. However, I can't vouch for its stability yet. The reviews of it are good, though.
如果您正在开发仅支持 iOS 5.0 或更高版本的应用程序,则可以使用 NSJSONSerialization.
If you're developing an application that is only iOS 5.0 or later, you can use NSJSONSerialization.