解析自定义的json数据
来源:互联网 发布:菜鸟网络创始人 编辑:程序博客网 时间:2024/05/01 21:16
Json是开发中常见的数据交换格式,对于一般的json数据,使用NSJSONSerialization完全够用,代码如下:
/** * Json的数据表如下 [{ "name":"Vincent", "age":"18", "tel":{ "home":"123", "comp":"456" } },{ "name":"Zander", "age":"21", "tel":{ "home":"789", "comp":"568" } }] */#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; NSString *path=[[NSBundle mainBundle]pathForResource:@"info" ofType:@"json"]; NSData *data=[NSData dataWithContentsOfFile:path]; //解析json字符串 NSArray *jsonArr=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; //循环输出后的解析结果 for (NSDictionary *dicty in jsonArr) { NSString *name=[dicty valueForKey:@"name"]; NSString *age=[dicty valueForKey:@"age"]; NSDictionary *telDict=[dicty valueForKey:@"tel"]; NSString *homeTel=[telDict valueForKey:@"home"]; NSString *compTel=[telDict valueForKey:@"comp"]; NSLog(@"姓名:%@---年龄:%@---家庭电话:%@---公司电话:%@",name,age,homeTel,compTel); } // Do any additional setup after loading the view, typically from a nib.}
0 0
- 解析自定义的json数据
- Json数据 解析的自定义方法
- json 的数据解析
- JSON数据的解析
- JSon数据的解析
- JSON数据的解析
- JSon数据的解析
- json的数据解析
- Json数据的解析
- JSON数据的解析
- JSON数据的解析
- json数据的解析
- JSON数据的解析
- Json数据的解析
- Json数据的解析
- Json数据的解析
- JSON数据数据的解析
- 【数据解析】Android Json数据的解析
- Java设计模式之代理模式
- java判断文件编码格式
- 浅谈HTTP中Get与Post的区别
- 用PIPEWORK为docker容器配置独立IP
- Java新手入门的30个基本概念
- 解析自定义的json数据
- DISPLAY=:0.0
- 如何少走弯路的10条忠告
- MagicalRecord dispatch_aync 多线程保存
- Android数据转换
- 空指针调用类的方法
- 安卓只在UI线程中更新UI 出现的例外
- Linux系统备份工具收罗
- 小红书计划之学习调用安卓系统照相机