Lenx van Zyl Lenx van Zyl - 10 months ago 59
JSON Question

Convert NSString to JSON

I am converting a

like so :


let newDict = try NSJSONSerialization.dataWithJSONObject(objectDictionaries, options: NSJSONWritingOptions.PrettyPrinted)
if let json = NSString(data: newDict, encoding: NSUTF8StringEncoding) {

When the
prints out I get this:

enter image description here

How do I convert this NSString to JSON without changing the format as this photo shows?
The I want to send this json to a API and the format I want is the only one the API will be able to encode,

Answer Source

Remove the option NSJSONWritingOptions.PrettyPrinted in the call to dataWithJSONObject. That is what is forcing the outputted string to be formatted like that.