Raptor Raptor - 2 years ago 214
iOS Question

Other options than NSJSONWritingPrettyPrinted?

I convert a

NSDictionary
to JSON
NSData
with the following line:

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:answers
options:NSJSONWritingPrettyPrinted
error:&err];


And pass it to server side, which is a PHP script. The script reads the JSON string as:

{
"A" : "1941",
"D" : "1699",
"B" : "1949",
"E" : "1823",
"C" : "1999"
}


How can I format the JSON string as 1 line, just like below?

{"A" : "1941", "D" : "1699", "B" : "1949", "E" : "1823", "C" : "1999"}


Is there any option other than
NSJSONWritingPrettyPrinted
?

Answer Source

Quoth the documentation for NSJSONWritingPrettyPrinted;

If this option is not set, the most compact possible JSON representation is generated.

If you don't want to set any bits in the writing options mask, just pass zero for that parameter. (Or in Swift, an empty option-set, which looks just like an empty array: [].)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download