//開始拼接Json字符串
ns dictionary * data dictionary =【ns dictionary withobjectsandkeys:@“MAC“,@“MAC“,
@“遊戲“,@“遊戲“,
@“設備令牌“,@“設備令牌“,
@“設備”,@“設備”,
@“靈臺”,@“靈臺”,
@“郎”,@“郎”,
@“OS“,@“OS“,nil】;
ns dictionary * parm dictionary =【ns dictionary withobjectsandkeys:@“getSession“,@“act“,
dataDictionary,@“data“,nil】;
ns dictionary * JSON dictionary =【ns dictionary dictionaryWithObjectsAndKeys:@“PV“,@“PV“,
parmDictionary,@“param“,nil】;
SBJsonWriter * writer =【【SBJsonWriter alloc】init】;
ns string * jasonString =【writer string with object:jsonDictionary】;
NSLog(@“% @”,Jason string);
上面的代碼使用了三層嵌套。請註意,在NSDictionary中,值在前面,鍵在後面。
縫合後的結果如下:
{“PV“:“PV“、“param“:{“act“:“getSession“、“data“:{“OS“:“OS“、“MAC“:“MAC“:“game“:“game“:“gv“:“gv“、“lang“:“lang“:“device token“:“device token“:“設備“:“設備“}}
使用Json在線驗證工具解析後:
{
“光伏”:“光伏”,
“param“:{
“act“:“getSession“,
"數據":{
“操作系統”:“操作系統”,
“MAC”:“MAC”,
“遊戲”:“遊戲”,
“靈臺”:“靈臺”,
“郎”:“郎”,
“設備令牌“:“設備令牌“,
“設備”:“設備”
}
}
}