JSON之解析通过TouchJSON\SBJSON\JSONKit\NSJSONSeriliz...
2015-06-21 16:43
621 查看
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];
"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];
相关文章推荐
- [LeetCode][JavaScript]Add Two Numbers
- swipe.js 2.0 轻量级框架实现mobile web 左右滑动
- [LeetCode][JavaScript]Median of Two Sorted Arrays
- js深入浅出(大纲)
- jsp——学习篇:建立第一个jsp程序
- position属性absolute与relative 详解 最近一直在研究javascript脚本,熟悉DOM中CSS样式的各种定位属性,以前对这个属性不太了解,从网上找到两篇文章感觉讲得很透彻,
- javascript错误处理与调试
- javascript学习笔记-4
- <jsp-config>标签使用详解
- JS(一)Prototype的使用
- js面向对象(一)
- js
- Jsoup做接口测试
- js三个关键对象(运行期)
- 浏览器中的Javascript的简单对话框
- js词法分析
- 利用js查找页面中的内链,外链
- js作用域
- Javascript运用函数计算正方形的面积
- javascript基础学习之-事件冒泡