I want to send an array via POST to a Django web service from my iOS app, and wanted to know if it was possible without serializing to JSON.
2 Answers
Although I don't have a great recommendation as to alternatives, for completeness here is a short example on how easy you can serialize a dictionary with the iOS integrated libraries (no external lib/tools needed):
// Dictionary convertable to JSON ?
if ([NSJSONSerialization isValidJSONObject:dict])
{
// Serialize the dictionary
json = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
// If no errors, let's view the JSON
if (json != nil && error == nil)
{
NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
NSLog(@"JSON: %@", jsonString);
}
}