使用"JSONKit.h"解析文件
来源:互联网 发布:14.04 linux 输入法 编辑:程序博客网 时间:2024/06/09 15:22
使用"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);
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);
0 0
- 使用"JSONKit.h"解析文件
- JSONKit解析
- IOS JSON解析之JSONKit使用
- IOS JSON解析之JSONKit使用
- 使用JsonKit解析中文时注意事项
- IOS JSON解析之JSONKit使用
- IOS JSON解析之JSONKit使用
- json解析使用第三方类库JSONKit
- IOS JSON解析之JSONKit使用
- IOS--JSON解析之JSONKit使用
- stirng 读取json文件 jsonkit 使用
- jsonkit 解析本地数据
- JSon解析之JSonKit
- iOS开发 JSONKit解析
- JSONKit网络解析
- emmintrin.h文件解析
- xmmintrin.h文件解析
- jni.h文件解析
- Yii集成Ueditor
- 黑马程序员_异常处理学习笔记
- 使用strace+pstack利器分析程序性能
- 一招一式练武功——读《软件方法上册——业务建模和需求》有感
- java.lang.VerifyError
- 使用"JSONKit.h"解析文件
- TIMESTEN安装配置指南-中文版
- 图的表示
- iPhone同步请求
- 慢下来的时光
- Java里的堆(heap)栈(stack)和方法区(method)
- TCP/IP详解学习笔记(1)-基本概念
- Python 信号量
- iPhone 动画图片