您的位置:首页 > 移动开发 > IOS开发

iOS开发 JSONKit解析

2016-03-25 22:12 375 查看
第四种方法:JSONKit

NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.weather.com.cn/data/sk/101260101.html"]];
__autoreleasing NSError *err;
//(-1).打开XX-Net的start.command,状态栏打开EnableGlobalProxy
//(0).搜到ip后登录github.com/johnezang/JSONKit里DownloadZip下载包解压
//(1).导入.h和.m。到工程并 #import "JSONkit.h”,
//(2).JSONkit编译选项添加-fno-objc-arc命令
//(3).AutoFixit两个废弃语法并忽略警告
//(4).待解析data使用objectFromJSONDataWithParseOption:方法
NSDictionary *dict=[data objectFromJSONDataWithParseOptions:JKSerializeOptionNone error:&err];
NSLog(@"城市:%@",dict[@"weatherinfo"][@"city"]);
NSLog(@"温度:%@℃",dict[@"weatherinfo"][@"temp"]);
NSLog(@"时间:%@",dict[@"weatherinfo"][@"time"]);
NSLog(@"湿度:%@",dict[@"weatherinfo"][@"SD"]);
李昌立 09:59:51
2016-03-25 09:58:48.284 ex14-json[30629:1492867] 城市:贵阳
2016-03-25 09:58:48.285 ex14-json[30629:1492867] 温度:17℃
2016-03-25 09:58:48.285 ex14-json[30629:1492867] 时间:10:00
2016-03-25 09:58:48.285 ex14-json[30629:1492867] 湿度:79%
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: