ios - 序列化 JSON 字符串 SBJSON vs NSJSONSerialization vs 其他?

标签 ios nsjsonserialization sbjson

我收到这个 JSON 字符串,想知道如何将它序列化到一个字典中,以便我可以将它解析为一个托管对象。

我已经研究了几种方法(如标题所示),但似乎找不到最简单、最快捷的替代方法。我想使用 NSJSONSerialization,但我不确定它是用来做这个的吗?

字符串所在的代码

NSString *data = [[NSString alloc]initWithData:response encoding:NSUTF8StringEncoding];
        NSLog(@"String %@",data);

NS日志消息

String [{"0":"1","id":"1","1":"re ee","name":"re ee","2":"http:\/\/ree.com\/images\/re.png","backgroundImageUrl":"http:\/\/ree.com\/images\/re.png","3":"http:\/\/ree.com\/images\/re.png","logoImageUrl":"http:\/\/ree.com\/images\/re.png"}]<br />

提前致谢

最佳答案

JSONKit是您正在寻找的。

除了易用性之外,它比 SBJSON 更快,甚至比 NSJSONSerialization 更快。

对于您的示例,您可以获得这样的数组:

NSArray* arrayFromJson = [data objectFromJSONString];
NSString* id = arrayFromJson[0][@"id"];

简单吧?

关于ios - 序列化 JSON 字符串 SBJSON vs NSJSONSerialization vs 其他?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15891825/

相关文章:

ios - 在我的 iOS 应用程序中与外部配件通信以播放流中的视频

ios - 将 "initWithNibName"更改为 "storyboardWithName"

ios - ViewController 未从内存中释放

objective-c - JSON : how to deal with double quotations?

json - SBJsonWriter 嵌套 NSDictionary

ios - 解析 Django 创建的 JSON

ios - 从文件应用程序拖放失败并出现 257 文件保护错误

objective-c - NSJSON 序列化

ios - 在 Swift 中用数组序列化我自己的对象的更优雅的方法是什么

ios - NSJSONSerialization 上的 exc_bad_instruction