JSON之解析通过TouchJSON\SBJSON\JSONKit\NSJSONSerialization

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写,同时也易于机器解析和生成。格式:{ "firstName": "a","secondName":"b" }

NSJSONSerialization是iOS5开始自带的JSON解析API,且效率较高,解析的速度快

TouchJSON\SBJSON\JSONKit是第三方库

下载链接:

TouchJSON:https://github.com/TouchCode/TouchJSON

SBJSON:https://github.com/stig/json-framework

JSONKit:https://github.com/johnezang/JSONKit

在解析的效率上NSJSONSerialization>JSONKit>TouchJSON>SBJSON

以下是解析http://m.weather.com.cn/data/101010100.html,获得天气的不同方法

JSON内容是{"weatherinfo":{"city":"北京","city_en":"beijing","date_y":"2013年3月9日",,,,,,,,}}多层嵌套

一.NSJSONSerialization

解析方法:

NSDictionary *weatherDic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];

案列:

二.JSONKit

解析方法:

#import "JSONKit.h"

1.

JSONDecoder *decoder=[[JSONDecoder alloc]init];

NSDictionary *weatherDic=[decoder objectWithData:data];

2.

NSDictionary *weatherDic=[data objectFromJSONData];

案列:

三.TouchJSON

解析方法:

#import "CJSONDeserializer.h"

NSDictionary *weatherDic=[[CJSONDeserializer deserializer]deserialize:data error:&error];

案列:

TouchJSON可以把对象转化为JSON:

#import "CJSONSerializer.h"

NSData *jsonData = [[CJSONSerializer serializer] serializeObject:dictionary  error:&error];

四.SBJSON

解析方法:

#import "SBJson.h"

SBJsonParser *parser=[[SBJsonParser alloc]init];

NSDictionary *weatherDic=[parser objectWithData:data];

案列:

转自http://my.oschina.net/LouWk/blog/112701

最新文章

  1. foreach的用法
  2. HDU2509 Be the Winner
  3. BeagleBone Black– 智能家居控制系统 LAS - ESP8266 UDP 服务
  4. --@angularJS--浅谈class与Ng-Class的应用
  5. 跨专业学习编程的苦逼生活 QWQ嘤嘤嘤
  6. 【Contest Hunter 5302】金字塔
  7. PHP导出MySQL数据字典 Summer-Mysql-Dic
  8. linux系统下键盘按键的重新映射——xmodmap工具和xev工具
  9. RHEL7 DNS 服务 unbound 测试
  10. [leetcode shell]194. Transpose File
  11. MJRefresh原理分析
  12. C# 通过Exchange server 发送邮件
  13. sqlmap使用帮助文档(1)
  14. 将list列表中unicode类型的值转换为字符串类型
  15. Word中高效输入公式:内嵌公式和Mathtype
  16. #leetcode刷题之路8-字符串转换整数 (atoi)
  17. HDU2031 进制转换
  18. 新建maven工程index.jsp页面报错
  19. No module named appium
  20. Java探索之旅(15)——包装类和字符类

热门文章

  1. 洛谷 P3387 【模板】缩点
  2. Mongodb之failed to create service entry worker thread
  3. VC 对话框设置背景颜色和图片
  4. Mycat实现读写分离、分库分表
  5. Lemonade Trade
  6. webpack配置指南
  7. C++调用C语言编译的so文件
  8. mysql crash cource 书中实例
  9. [vijos]P1979 NOIP2015 信息传递
  10. 洛谷 P3328 【[SDOI2015]音质检测】