JSON处理
来源:互联网 发布:ipad怎么看淘宝直播间 编辑:程序博客网 时间:2024/06/06 03:12
<span style="font-family: Arial, Helvetica, sans-serif;">// 创建JSON对象</span>
- (void)createJsonObj{ NSNumber *age = [NSNumber numberWithInt:25]; NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"麦子",@"name",@"男",@"sex",age,@"age", @"六中",@"school",@"湖南",@"area", nil]; NSDictionary *dicA = [[NSDictionary alloc] initWithObjectsAndKeys:@"小麦子",@"name",@"男",@"sex",age,@"age", @"六中",@"school",@"湖南",@"area", nil]; NSArray *arrayData = [[NSArray alloc] initWithObjects:dic,dicA, nil]; // 字典数据转JSON NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arrayData options:NSJSONWritingPrettyPrinted error:nil]; // 数据打印 NSString *str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; NSLog(@"%@",str);}// 解析JSON- (void)preJSONData{ NSURL *url = [[NSURL alloc] initWithString:@"http://weather.com.cn/adat/cityinfo/101010100.html"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; NSData *requestData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; // NSString *str = [[NSString alloc] initWithData:requestData encoding:NSUTF8StringEncoding]; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:requestData options:NSJSONReadingMutableLeaves error:nil]; // 对于返回的是数组的时候,就这样。 这个方法返回的是一个id类型 NSArray *dicArray = [NSJSONSerialization JSONObjectWithData:requestData options:NSJSONReadingMutableLeaves error:nil]; NSDictionary *weatherDic = [dic objectForKey:@"weatherinfo"]; for (NSString *str in [weatherDic allKeys]) { NSLog(@"%@---%@",str,[weatherDic objectForKey:str]); } }
0 0
- JSON处理
- 处理json
- json处理
- JSON处理
- JSON处理
- json处理
- js json.js处理json
- 用 JSON 处理缓存
- 用 JSON 处理缓存
- 用javascript处理JSON
- 用JSON处理缓存!
- json处理,填充select
- Ajax/Json乱码处理
- JSON处理方法
- JSON通用服务端处理
- JAVA处理JSON学习
- javescript 处理json
- JavaScript处理Json
- JS的碰撞周期移动
- LeetCode Maximum Subarray
- Glibc configure error: The arm is not supported.
- 编写多进程程序 --多进程编程
- Arduino MPU6050学习资料总结
- JSON处理
- 关于Toast在页面重复显示,非本页面显示
- 10001--数据库的隔离级别
- Windows 驱动开发 - 8
- Android点击—20150628【附带讲解IOS和娜姐界面】
- JSONObject与JSONArray的使用
- 绑定focus事件的函数里绑定键盘事件造成的冲突?错误?
- 深入学习Service
- 持久化对象的状态