iOSJsonKit的使用
2015-04-15 09:34
369 查看
转自:http://blog.csdn.net/cuiweijie3/article/details/9174739
ios开发中JSONKit的使用
C代码
NSLog(@"打印测试");
NSString *jsonstring =@"[{\"age\":18,\"book\":{\"price\":23.2,\"title\":\"boook111\"},\"name\":\"samyou\"},{\"age\":22,\"book\":{\"price\":33,\"title\":\"booook222\"},\"name\":\"samsam\"}]";
NSData *data=[jsonstring dataUsingEncoding:NSUTF8StringEncoding];
NSArray *arr=(NSArray *)[data mutableObjectFromJSONData];
NSLog(@"count=%d",arr.count);
for(int i=0;i<arr.count;i++)
{
NSDictionary *people=[arr objectAtIndex:i];
NSString *name=[people objectForKey:@"name"];
NSString *age=[people objectForKey:@"age"];
NSLog(@"person withname=%@,age=%d",name,[age intValue]);
NSDictionary *book=[people objectForKey:@"book"];
NSString *bookname=[book objectForKey:@"title"];
NSNumber *price=[book objectForKey:@"price"];
NSLog(@"book with title=%@,price=%f",bookname,[price doubleValue]);
}
C代码
//比如 strJson 是网络上接收到的 json 字符串,
#import "JSONKit.h"
NSString *strJson = @"{\"aps\": {\"alert\":{\"body\":\"a msg come!\"},\"bage\":3,\"sound\":\"def.mp3\"}}";
NSDictionary *result = [jsonData objectFromJSONData];
C代码
NSMutableDictionary *jsonDic = [NSMutableDictionary dictionary];
NSMutableDictionary *alert = [NSMutableDictionary dictionary];
NSMutableDictionary *aps = [NSMutableDictionary dictionary];
[alert setObject:@"a msg come!" forKey:@"body"];
[aps setObject:alert forKey:@"alert"];
[aps setObject:@"3" forKey:@"bage" ];
[aps setObject:@"def.mp3" forKey:@"sound"];
[jsonDic setObject:aps forKey:@"aps"];
NSString *strJson = [jsonDic JSONString];
用法:
1.dictionary------>json
NSString *jsonstring = [dictionary JSONString];
2.json------------>dictionary
NSDictionary *dictionary = [jsonstring objectFromJSONString];
ios开发中JSONKit的使用
C代码
NSLog(@"打印测试");
NSString *jsonstring =@"[{\"age\":18,\"book\":{\"price\":23.2,\"title\":\"boook111\"},\"name\":\"samyou\"},{\"age\":22,\"book\":{\"price\":33,\"title\":\"booook222\"},\"name\":\"samsam\"}]";
NSData *data=[jsonstring dataUsingEncoding:NSUTF8StringEncoding];
NSArray *arr=(NSArray *)[data mutableObjectFromJSONData];
NSLog(@"count=%d",arr.count);
for(int i=0;i<arr.count;i++)
{
NSDictionary *people=[arr objectAtIndex:i];
NSString *name=[people objectForKey:@"name"];
NSString *age=[people objectForKey:@"age"];
NSLog(@"person withname=%@,age=%d",name,[age intValue]);
NSDictionary *book=[people objectForKey:@"book"];
NSString *bookname=[book objectForKey:@"title"];
NSNumber *price=[book objectForKey:@"price"];
NSLog(@"book with title=%@,price=%f",bookname,[price doubleValue]);
}
C代码
//比如 strJson 是网络上接收到的 json 字符串,
#import "JSONKit.h"
NSString *strJson = @"{\"aps\": {\"alert\":{\"body\":\"a msg come!\"},\"bage\":3,\"sound\":\"def.mp3\"}}";
NSDictionary *result = [jsonData objectFromJSONData];
C代码
NSMutableDictionary *jsonDic = [NSMutableDictionary dictionary];
NSMutableDictionary *alert = [NSMutableDictionary dictionary];
NSMutableDictionary *aps = [NSMutableDictionary dictionary];
[alert setObject:@"a msg come!" forKey:@"body"];
[aps setObject:alert forKey:@"alert"];
[aps setObject:@"3" forKey:@"bage" ];
[aps setObject:@"def.mp3" forKey:@"sound"];
[jsonDic setObject:aps forKey:@"aps"];
NSString *strJson = [jsonDic JSONString];
用法:
1.dictionary------>json
NSString *jsonstring = [dictionary JSONString];
2.json------------>dictionary
NSDictionary *dictionary = [jsonstring objectFromJSONString];
相关文章推荐
- IOS开发之jsonkit使用简介
- ios开发中JSONKit的使用
- IOS JSON解析之JSONKit使用
- ios jsonkit 使用测试
- iOS不使用JSONKit做Dic到JsonString的转换
- IOS--JSON解析之JSONKit使用
- IOS之JSONKit的使用
- IOS中Json解析的四种方法,推荐使用原生解析,和jsonKit
- iOS程序猿之JSONKit的使用
- 【代码笔记】iOS-JSONKit的使用
- 【代码笔记】iOS-JSONKit的使用
- iOS SnapKit自动布局使用详解(Swift版Masonry)
- iOS JSONModel使用
- iOS开发学习专题-基础知识(三)NSDictionary字典NSMutableDictionary可变字典NSDictionary字典和json转换详细使用方式
- Jfinal 使用JsonKit.parse 报错解决
- iOS开源项目:JSONKit
- iOS JSONKit(了解)
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取"产品付费数量等于0的问题"】
- <转>iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!
- ios中使用 NSJSONSerialization对 json数据的解析