IPHONE JSON 一个例子
来源:互联网 发布:admaster数据分析岗 编辑:程序博客网 时间:2024/05/16 20:30
Objective-C
Works with: Mac OS X version 10.7+
untested
NSString *json_string = @"{ \"foo\": 1, \"bar\": [10, \"apples\"] }"; id obj =[NSJSONSerialization JSONObjectWithData:[json_string dataUsingEncoding:NSUTF8Encoding] options:0 error:NULL]; NSLog(@"%@", obj); idobj2 = [NSDictionary dictionaryWithObjectsAndKeys:[NSArrayarrayWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithInt:2], nil],@"blue", @"water", @"ocean", nil]; NSString *json_string2 = [[[NSString alloc]initWithData:[NSJSONSerialization dataWithJSONObject:obj2 options:0 error:NULL]encoding:NSUTF8Encoding] autorelease]; NSLog(@"%@", json_string2);