iOS development--using Sbjson to stitch JSON strings

Source: Internet
Author: User

The Sbjson package is in the previous article.

The ability to use key-value pairs in nsdictionary to splice JSON data is convenient and 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.

The results of stitching 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"        }    }}


iOS development--using Sbjson to stitch JSON strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.