NSMutableDictionary *params = [NSMutableDictionary dictionary]; //我们要上传的子参数字典
params[@"xxx"] = @"xxx"; //字典内容设置
//重点来了!
NSError *error;
NSData * jsonData = [NSJSONSerialization dataWithJSONObject: params options:NSJSONWritingPrettyPrinted error:&error]; //第一步,字典转数据
NSString *jsonString = [[NSString alloc]initWithData: jsonData encoding:NSUTF8StringEncoding]; //第二部,数据转JSON
NSString *outerJson = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error]; //第三步,处理JSON,去掉“\”转义
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; //定义新字典存参
dictionary[@"data"] = outerJson; //将处理好的JSON存入key中
附加:
post需求:参数名称-data
参数结构:{
"xxx": "xxxxxx",
"xxxx": [
{
"xxxx": "xxxx",
"xxxx": "xxxx"
}
]
}