iPhone上的JSON
来源:互联网 发布:1942河南大饥荒 知乎 编辑:程序博客网 时间:2024/06/11 19:57
原帖地址:http://c.gzl.name/archives/category/cocoa/cobjc
JSON我就不多解释了,需要更多信息的朋友请到json.org上查看。
在iPhone上访问网络内容是很必须的,而一些数据就需要以某种形式储存在web服务器上。比如一个app的目录,内容,索引等等。而xml和json,plist都是比较方便的方式。
-XML在iPhone上是非常好用的,但是对复杂的数据结构使用上就不那么方便了,具体可以参阅苹果的“基于事件的XML”和“基于树的XML”编程向导
-plist是再方便不过了,不过我看最多也就是一个NSDictionary而已,复杂一些的话,数据输入上也会非常非常的麻烦。
-JSON本来是不被苹果支持的,但是有人很Nice的帮我们解决了这个问题:JSON for OBJC http://code.google.com/p/json-framework/
基本上来说,这个框架异常的简单易用,会将得到的json字符串处理成一个复杂NSDictionary对象,而每一个值都还是一个NSDictionary对象
比如:
{"华藏净宗学会":{"zhaomu":{"name":"净宗朝暮课本","length":142,"digits":3},"kesong":{"name":"净宗共修课本","length":75,"digits":2}},"生命基金会":{"dabei88":{"name":"大悲出相图","length":88,"digits":2}}}
就会转换为一个复杂无比的NSDictionary:
[[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects: [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: @"净宗朝暮课本", @"142", @"3",nil] forKeys: [NSArray arrayWithObjects: @"name", @"length", @"digits",nil]], [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: @"净宗共修课本", @"75", @"2",nil] forKeys: [NSArray arrayWithObjects: @"name", @"length", @"digits",nil]],nil] forKeys:[NSArray arrayWithObjects:@"zhaomu",@"kesong",nil]], [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: @"大悲出相图", @"88", @"2",nil] forKeys: [NSArray arrayWithObjects: @"name", @"length", @"digits",nil]],nil] forKeys:[NSArray arrayWithObjects:@"dabei88",nil]],nil] forKeys:[NSArray arrayWithObjects:@"华藏净宗学会",@"生命基金会",nil]];
我是非常佩服自己能打出来上面的巨大无比的定义式。。。。没有编译错误
不管怎么样,转换后,在系统中就可以非常方便的使用json的键值结构信息咯~!!!
- iPhone上的JSON
- iPhone上的JSON
- iPhone上的JSON
- iPhone上的JSON(一)
- iPhone上的JSON(二)
- iPhone上的JSON(二)
- iPhone平台上的json-framework
- iPhone平台上的json-framework
- iPhone上的JSON(三)JSON+UITableView
- iPhone上的JSON(三)JSON+UITableView
- iPhone上的JSON(三)JSON+UITableView
- iPhone上的JSON,NSArray,NSSet,NSDictionary总结
- iphone json的使用
- iPhone上的电子表格软件
- iPhone上的OpenAL音频
- iphone上sqlite3的使用
- iPhone上的OpenAL音频
- iphone开发之Json数据的解析
- Spring的核心机制依赖注入简介
- Spring的核心机制依赖注入简介
- HTML5新增标签
- VC下实现多项式的加减乘除
- 在Visual C++中如何利用UDL文件来建立ADO连接
- iPhone上的JSON
- iphone 绘图小结
- 关于软件测试停止标准
- 注册表遍历
- QT中对Windows API的应用
- retain和copy的区别
- 视线语音鼠标 7 人脸检测-形态学运算
- 将Python程序打包为Windows可执行文件格式
- 桥接方式下虚拟机在局域网的通信问题