ios5中的nsjson序列化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6726899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nsjsonserialization in ios5?
提问by user483044
I have been reading that there is a now library in ios 5 that allows you to serialize & deserialize JSON data. I can't for the life of me find examples or the framework in my /Developer folder. Anyone have luck locating/working with this? If so could you please point me in the right direction?
我一直在读到 ios 5 中有一个 now 库,它允许您序列化和反序列化 JSON 数据。我一生都无法在我的 /Developer 文件夹中找到示例或框架。有没有人有幸找到/使用这个?如果是这样,你能指出我正确的方向吗?
回答by Drew C
NSJSONSerializationis now public in iOS 5, and there's an example of its use in the Tweetingsample app.
NSJSONSerialization现在在 iOS 5 中是公开的,并且有一个在Tweeting示例应用程序中使用它的示例。
回答by calamandurrio
I'm using it and it's quite simple, just import the library:
我正在使用它,它很简单,只需导入库:
#import <Foundation/NSJSONSerialization.h>
and begin to use it.
并开始使用它。
Here there's a small but good tutorial: http://pragprog.com/magazines/2011-11/inside-ios-
这里有一个小而好的教程:http: //pragprog.com/magazines/2011-11/inside-ios-
回答by Coredumped
It is actually part of the Foundation framework, been trying to use it since last night and for the purpose of actually serializing a dictionary to a JSON representation it works quite fine. Sadly I've not tested it the other way around. Trust me the doc is there and it is no private API, sadly as you observed there are no examples.
它实际上是 Foundation 框架的一部分,从昨晚开始就一直在尝试使用它,为了将字典实际序列化为 JSON 表示,它工作得很好。可悲的是,我还没有反过来测试它。相信我,文档就在那里,它不是私有 API,遗憾的是,正如您所观察到的那样,没有示例。
回答by brainjam
I stumbled across iOS5 JSON support in this tutorial, which is part of an excellent series of iOS5 tutorials.
我在本教程中偶然发现了 iOS5 JSON 支持,它是优秀的 iOS5 教程系列的一部分。
回答by iDroid
Now iOS5 itself has the ability to serialize and de-serialize the json objects,
it will manage all the process behind the scene, and you will be getting easily
customizable foundation objects (NSArray,NSDictionary,NSString...)
Based on your flavor you represented.
As brainjam suggest This is the good tutorial to begin with. Hope your fingers can play around with json objects easily.
现在的iOS5本身所具有的能力,序列化和反序列化JSON对象,
它会管理所有的过程在幕后,你会越来越容易
定制的基础对象(的NSArray,NSDictionary中,NSString的...)
根据您的口味,你代表。
正如 Brainjam 所建议的,这是一个很好的教程。希望你的手指可以轻松地玩弄 json 对象。
回答by amitshinik
Using following simple code you can convert web data into JSON .
使用以下简单代码,您可以将 Web 数据转换为 JSON 。
In this code "webData" is the data you get when you hit web service.
在这段代码中," webData" 是您点击 Web 服务时获得的数据。
NSError *jsonParsingError = nil;
NSArray *result=[NSJSONSerialization JSONObjectWithData:webData options:0 error:&jsonParsingError];

