iOS网络请求传入数组
2016-12-22 本文已影响756人
这一颗心
iOS网络请求传入数组
之前做项目的时候,后台要求传入数组,用AFN传入字典,代码入下:
NSDictionary *parameter = [ NSDictionary dictionary];
NSArray *arr = @[parameter];
NSError *parseError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&parseError];
NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSData *objectData = [jsonstr dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:&parseError];