NSMutableDictionary*dictionary = [[NSMutableDictionary alloc]init];
[dictionary setValue:@"hello"forKey:@"one"];
[dictionary setValue:@"world"forKey:@"two"];
NSArray *array=[NSArray arrayWithObjects:@"001",@"002",@"003",nil];
[dictionary setValue:array forKey:@"three"];
NSData*data=[NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
NSString*jsonStr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"jsonStr==%@",jsonStr);
输出结果为:
str=={
"one" : "hello",
"two" : "world",
"three" : [
"001",
"002",
"003"
]
}
NSMutableDictionary*dictionary = [[NSMutableDic