使用"JSONKit.h"解析文件

使用"JSONKit.h"解析的步骤:
1 获取文件地址
2 将文件内容赋给字符串
3 将字符串转换为NSData
4 jiangNSData转换为字典
5 使用键值取出字典的内容

代码:
NSString * resourcePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"txt"];
NSString * strJson = [NSString stringWithContentsOfFile:resourcePath encoding:NSUTF8StringEncoding     error:NULL];

NSData* jsonData = [strJson dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* resultDic = [jsonData objectFromJSONData];
NSLog(@"resultDic = %@",resultDic);

NSDictionary * weatherinfoArray = [resultDic objectForKey:@"weatherinfo"];
NSLog(@"weatherinfoArray = %@",weatherinfoArray);

NSString * w1city = [weatherinfoArray objectForKey:@"city"];
self.textCity.text = w1city;
NSLog(@"w1city = %@",w1city);

NSString * w1city_en = [weatherinfoArray objectForKey:@"city_en"];
self.textPinyin.text = w1city_en;
NSLog(@"w1city_en = %@",w1city_en);

NSString * w1date_y = [weatherinfoArray objectForKey:@"date_y"];
self.textDate.text = w1date_y;
NSLog(@"w1date_y = %@",w1date_y);

NSString * w1img_title2 = [weatherinfoArray objectForKey:@"img_title2"];
self.teatWeacher.text = w1img_title2;
NSLog(@"w1img_title2 = %@",w1img_title2);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值