NSMutableDictionary*dictionary = [[NSMutableDictionaryalloc]init];
[dictionary setValue:@"hello" forKey:@"one"];
[dictionary setValue:@"world" forKey:@"two"];
NSArray*arry=[NSArrayarrayWithObjects:@"001",@"002",@"003",nil];
[dictionary setValue:arry forKey:@"three"];
NSData*data=[NSJSONSerializationdataWithJSONObject:dictionaryoptions:NSJSONWritingPrettyPrintederror:nil];
NSString*jsonStr=[[NSStringalloc]initWithData:dataencoding:NSUTF8StringEncoding];
NSLog(@"jsonStr==%@",jsonStr);
输出结果为:
str=={
"one" : "hello",
"two" : "world",
"three" : [
"001",
"002",
"003"
]
}
版权声明:本文为Dlg1992原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。