码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 使用SBJSON创建和解析JSON

时间:2015-06-05 15:32:37      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

原文地址:http://blog.csdn.net/gf771115/article/details/7718403

//创建JSON
NSDictionary *dictonary = [[NSMutableDictionary alloc] init];
[dictonary setValue:@"MIle" forKey:@"name"];
[dictonary setValue:@"19" forKey:@"age"];
[dictonary setValue:@"male" forKey:@"sex"];
NSDictionary *root = [[NSMutableDictionary alloc] init];
[root setValue:dictonary forKey:@"player"];

SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSLog(@"Start Create JSON!");
NSString *value = [writer stringWithObject:root];
NSLog(value);

//解析JSON
NSDictionary *dicRoot = [[[SBJsonParser alloc]init] objectWithString:value];
for (int i=0; i<[dicRoot count]; i++) {
NSDictionary *player = [dicRoot objectForKey:@"player"];
NSString *name = [player objectForKey:@"name"];
NSString *age = [player objectForKey:@"age"];
NSString *sex = [player objectForKey:@"sex"];
NSLog(@"Name = %@", name);
NSLog(@"Age = %@", age);
NSLog(@"Sex = %@", sex);

}

iOS 使用SBJSON创建和解析JSON

标签:

原文地址:http://www.cnblogs.com/wvqusrtg/p/4554675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!