0

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.

1
  • 3
    You have to serialise it to something. What's wrong with JSON? Commented Jan 25, 2014 at 20:42

2 Answers 2

1

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);
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

One way of doing this would be sending it as a plain text and then parse it at the receiving end and cast it to array again. But then any developer would hate using it, and as publisher you would hate maintaining it(ever a period of time).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.