Imran Shams Imran Shams - 5 months ago 130
Swift Question

Parse UTF8 json file in swift not work correctly with SwiftyJson

I tried to load UTF8 JSON file in swift and I received response in

NSData
. Then I converted it to
NSString
by:

let responseString = NSString(data: myNSdata!, encoding: NSUTF8StringEncoding)
let json = JSON(responseString)
print(json["now"].string)
print(json.string)


First print show nil but second print show file correctly but there is
\
char before each
"
and I think this is the reason. Please help me to find solution.

Answer

No need to make a string to init JSON(), do it with the data:

let json = JSON(data: myNSdata!)
Comments