简体   繁体   中英

POSTING json with nested objects to server

This is my first native iOS app, so please bear with..

How would I construct this json data in a NSDictionary (I would guess thats how I would do it) so I cand make it part of my request body.

    {
        "Properties":{
           "Description":"String content",
           "Domain":"String content",
           "GroupID":"String content", 
           ...
       },
       "Foo":{....},
   }

Yes, use a dictionary, created using literals or code.

NSDictionary* jsonDict = @{@"Properties":@{@"Description":@"String content",@"Domain":@"String content",@"GroupID":@"String content",},@"Foo":{....},}

Convert the dictionary into JSON data ready for posting.

NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:&error];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM