美文网首页ios
iOS post请求向服务器发送json格式数据(数组或字典)

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

作者: 孤胆走天涯 | 来源:发表于2016-01-18 09:14 被阅读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)参数,换成数组就可以了

相关文章

网友评论

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

    本文链接:https://www.haomeiwen.com/subject/ihdkkttx.html