作者:缪宇驰 | 来源:互联网 | 2023-09-13 06:33
NSMutableDictionary *dictionary[[NSMutableDictionary alloc] init]; [dictionary setValue:
NSMutableDictionary *dictiOnary= [[NSMutableDictionary alloc] init];
[dictionary setValue:@"hello" forKey:@"one"];
[dictionary setValue:@"world" forKey:@"two"];
NSArray *arry=[NSArray arrayWithObjects:@"001",@"002",@"003", nil];
[dictionary setValue:arry forKey:@"three"];
NSData *data=[NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsOnStr=[[NSString alloc]initWithData:dataencoding:NSUTF8StringEncoding];
NSLog(@"jsOnStr==%@",jsonStr);
输出结果为:
str=={
"one" : "hello",
"two" : "world",
"three" : [
"001",
"002",
"003"
]
}