NSMutableDictionary *params = [NSMutableDictionary dictionary]; ?//我們要上傳的子參數(shù)字典
params[@"xxx"] = @"xxx"; ?//字典內(nèi)容設(shè)置
//重點來了床三!
NSError *error;?
NSData * jsonData ?= ?[NSJSONSerialization dataWithJSONObject: params options:NSJSONWritingPrettyPrinted error:&error]; ?//第一步芹枷,字典轉(zhuǎn)數(shù)據(jù)
NSString *jsonString = [[NSString alloc]initWithData: jsonData encoding:NSUTF8StringEncoding]; ?//第二部疏旨,數(shù)據(jù)轉(zhuǎn)JSON
NSString *outerJson = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]?options:NSJSONReadingAllowFragments error:&error]; ?//第三步上荡,處理JSON哎壳,去掉“\”轉(zhuǎn)義
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; ?//定義新字典存參
dictionary[@"data"] = outerJson; ?//將處理好的JSON存入key中
附加:
? ? post需求:參數(shù)名稱-data
? ? ? ? ? ? ? ? ? ? 參數(shù)結(jié)構(gòu):{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "xxx": "xxxxxx",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "xxxx": [ ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"xxxx": "xxxx",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"xxxx": "xxxx"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?]
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }