#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDictionary *jsonDict = @{@"name":@"Tom",@"age":@20};
NSData *data = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:nil];
NSLog(@"data = %@", data);
//打印结果:data = <7b226e61 6d65223a 22546f6d 222c2261 6765223a 32307d>
//json字符串转换为json对象
NSString *jsonString = @"{\"name\": \"xioahong\"}";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *resultDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
NSLog(@"result: %@", resultDict);
/*打印结果:result: {
name = xioahong;
} */
}
return 0;
}