您的位置:首页 > Web前端 > JavaScript

使用"JSONKit.h"解析文件

2014-04-01 18:23 531 查看
使用"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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐