ios

iOS post请求向服务器发送json格式数据(数组或字典)

2016-01-18  本文已影响6095人  孤胆走天涯

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是转换json格式的字典)

2.数组

数组其实和字典一样,只需将(dataWithJSONObject:dicFriends)参数,换成数组就可以了

上一篇 下一篇

猜你喜欢

热点阅读