The Sbjson package is in the previous article.
You can use key-value pairs in nsdictionary to splice JSON data, which is very convenient, or can be nested, directly on the code:
Start stitching the JSON string nsdictionary *datadictionary= [nsdictionary dictionarywithobjectsandkeys:@ "Mac", @ "Mac", @ "Game", @ "game", @ "Devicetoken", @ "Devicetoken", @ "Device" @ "Device" @ "GV" @ "GV" @ "Lang" @ "Lang", @ "OS", @ "OS", nil]; Nsdictionary *parmdictionary= [nsdictionary dictionarywithobjectsandkeys:@ "getsession", @ "Act", datadictionary,@ "Data", nil]; Nsdictionary *jsondictionary=[nsdictionary dictionarywithobjectsandkeys:@ "PV", @ "PV", Parm dictionary,@ "Param", nil]; Sbjsonwriter *writer = [[Sbjsonwriter alloc] init]; NSString *jasonstring = [writer Stringwithobject:jsondictionary]; NSLog (@ "%@", jasonstring);
The above code uses three layers of nesting, note that in Nsdictionary, the front is the value, followed by the key.
After stitching the results are as follows:
{"PV": "PV", "param": {"act": "GetSession", "data": {"OS": "OS", "Mac": "Mac", "Game": "Game", "GV": "GV", "Lang": "Lang", " Devicetoken ":" Devicetoken "," Device ":" Device "}}}
After parsing using the JSON online validation tool:
{ "PV": "PV", "param": { "act": "GetSession", "data": { "OS": "OS", " Mac": "Mac", " Game" : "Game", "GV": "GV", "lang": "Lang", "Devicetoken": "Devicetoken", "Device": "Device" } }}