1.字典
NSMutableDictionary *dicFriends = [[NSMutableDictionary alloc] init];
[dicFriends setObject:friends forKey:@"usernames"];
NSData *dataFriends = [NSJSONSerialization dataWithJSONObject:dicFriends options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:dataFriends
encoding:NSUTF8StringEncoding];
(ps? usernames 是字段,jsonString是轉(zhuǎn)換json格式的字典)
2.數(shù)組
數(shù)組其實(shí)和字典一樣,只需將(dataWithJSONObject:dicFriends)參數(shù),換成數(shù)組就可以了