[问题] NSArray 和JSON 和NSData的转换

楼主: meanjs (测试中文)   2017-02-01 16:15:03
想请问一下 目前的问题是 我需要透过HTTP传送出JSON array的资料
但转换成NSData之后 对方收到的格式有误 想请问一下有什么解法
//很单纯的array
NSArray *array = [ [ NSArray alloc ] initWithObjects:@"aa",@"bb",nil];
NSMutableURLRequest * request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10];
[request setHTTPBody:[NSJSONSerialization dataWithJSONObject:array options:0 error:nil]];
想要转成下面格式 对方才能收到
[
{aa},
{bb}
]
实际上 对方收到的格式
{
{aa},
{bb}
}
作者: tentenlee (天天)   2017-02-01 18:44:00
看你的code应该是收到["aa","bb"]吧
作者: shinrenpan (iOS5)   2017-02-01 21:16:00
NSJSONSerialization 转成的 NSData 要再转吧.

Links booklink

Contact Us: admin [ a t ] ucptt.com