标签:
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSMutableDictionary *dict=[[NSMutableDictionary alloc]init]; [dict setObject:@"1" forKey:@"one"]; dict[@"dc"]=@{@"two":@"2"}; NSLog(@"dict:%@",dict); NSData *data=[NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil]; NSString *str=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"JsonStr:%@",str); } return 0; } /打印结果为:dict:{ dc = { two = 2; }; one = 1; } 2015-10-23 16:43:25.025 Test110[6562:614592] JsonStr:{ "one" : "1", "dc" : { "two" : "2" } }
NSMutableDictionary转化为JSON字符串数据样例
标签:
原文地址:http://my.oschina.net/u/2410306/blog/521280