TouchJSON and SBJSON
来源:互联网 发布:淘宝客服回复快捷短语 编辑:程序博客网 时间:2024/05/21 14:55
- (void)viewDidLoad
{
[superviewDidLoad];
// 原始json字符串
NSString *jsonStringSrc =@"{\"attributes\":{\"StreetName\":\"MASON\",\"StreetType\":\"ST\"},\"address\":\"1 MASON ST\",\"score\":\"75\"}";
NSData *jsonData = [jsonStringSrcdataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dictionary = [[CJSONDeserializerdeserializer] deserializeAsDictionary:jsonDataerror:nil];
NSLog(@"parse: %@", dictionary);
//构建json值
NSDictionary *attributesDict =[NSDictionarydictionaryWithObjectsAndKeys:@"MASON",@"StreetName", @"ST",@"StreetType", nil];
NSDictionary *user1 =[NSDictionarydictionaryWithObjectsAndKeys:@"1 MASON ST",@"address", @"75",@"score", attributesDict, @"attributes",nil];
NSDictionary *user2 =[NSDictionarydictionaryWithObjectsAndKeys:@"2 MASON ST",@"address", @"75",@"score", attributesDict, @"attributes",nil];
NSDictionary *str1 = [NSDictionarydictionaryWithObjectsAndKeys:[NSArrayarrayWithObjects:user1, user2, nil],@"downLoadInfo",nil];
jsonData = [[CJSONSerializerserializer] serializeObject:str1error:nil];
NSString *jsonString2 = [[NSStringalloc] initWithData:jsonDataencoding:NSUTF8StringEncoding];
//touch json序列化
NSLog(@"\n1111111111------touch json: %@", jsonString2);
//SBJson序列化
NSLog(@"\n22222222222222------SBJson: %@", [str1JSONRepresentation]);
}
//SBJSON解析
{
"listJsonString":"[
{\"password\":\"111\",\"userName\":\"111\"},
{\"password\":\"222\",\"userName\":\"222\"},
{\"password\":\"333\",\"userName\":\"333\"}
]"
}
- (void)requestFinished:(ASIHTTPRequest *)request {
NSString *tempJson = [requestresponseString];
NSLog(@"%@",tempJson);
NSDictionary *dic = [tempJsonJSONValue];
NSArray *arr = [[dicobjectForKey:@"listJsonString"]JSONValue];
for (int i =0; i < [arr count]; i++) {
NSDictionary *temp = [arrobjectAtIndex:i];
NSLog(@"名字:%@,密码:%@",[tempobjectForKey:@"userName"],[tempobjectForKey:@"password"]);
UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(10,70 + i * 60,200, 50)];
label.text = [NSStringstringWithFormat:@"名字:%@,密码:%@",[tempobjectForKey:@"userName"],[tempobjectForKey:@"password"]];
[self.viewaddSubview:label];
[labelautorelease];
}
- TouchJSON and SBJSON
- JSON之解析通过TouchJSON\SBJSON\JSONKit\NSJSONSeriliz...
- JSON之解析通过TouchJSON\SBJSON\JSONKit\NSJSONSeriliz...
- TouchJson
- IOS中四种解析JSON的方法(IOS5自带支持方法、JSONKit、SBJson、TouchJson)
- SBJson
- SBJson
- SBJson
- Conversion between json and object using SBJson lib
- TouchJSON 用法
- iphone touchjson
- TouchJSON网络数据解析
- 使用SBJson
- SBJson用法
- SBJson库
- Sbjson教程
- SBJson解析
- Parsing JSON With SBJSON
- Java时间格式转换大全
- DialogResult
- Linux per_cpu机制的详解
- 《加班,谁之过?》
- VS2008与VC6.0的变化
- TouchJSON and SBJSON
- css实现两边对齐
- BlazeDs中获取servlet上下文
- 编写高质量代码:改善c#程序的157个建议之“避免锁定不恰当的同步对象”
- onInterceptTouchEvent和onTouchEvent调用时序
- 析构函数声明为虚函数
- 使用TightVNC在WinXP上远程管理Mac
- 获取其他应用程序的context
- thanking in java 学习笔记之2