Reputation: 3442
I need to create a POST request and in it's body I need to put a JSON. The template for the JSON file is as follows:
{"key" : [{...}, {...}, {...} ..... ]}
What I've tried doing is something like this:
@{@"key" : @[@{...}, @{...} ... ]};
The issue I have is that it puts round brackets around the NSArray
.
This is the output:
{key = ({...}, {...}, ..... )}
Snippet from my code(after I've created the NSDictionary
)
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myDictionary
options:NSJSONWritingPrettyPrinted
error:&error];
[request setHTTPBody:jsonData];
Is there a way for me to make the NSArray
have [ ]
instead of ( )
?
Upvotes: 0
Views: 514
Reputation: 119021
NSLog uses {} for printing NSDictionary and () for printing NSArray contents. This has nothing to do with JSON. Your JSON data structure is created and encoded correctly. To verify do this:
NSLog(@"%@", [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
And you will see that the actual JSON is printed.
Upvotes: 1