Create an array or dictionary of objects representing the information you want to send via JSON. Once done, send -JSONRepresentation
to the array / dictionary. This method returns a JSON string, and you send it to the server.
For example:
NSDictionary *o1 = [NSDictionary dictionaryWithObjectsAndKeys: @"some value", @"key1", @"another value", @"key2", nil]; NSDictionary *o2 = [NSDictionary dictionaryWithObjectsAndKeys: @"yet another value", @"key1", @"some other value", @"key2", nil]; NSArray *array = [NSArray arrayWithObjects:o1, o2, nil]; NSString *jsonString = [array JSONRepresentation];
After executing the above code, jsonString
contains:
[ { "key1": "some value", "key2": "another value" }, { "key1": "yet another value", "key2": "some other value" } ]
user557219
source share