Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swiftyjson cannot convert rawstring back to a json object

I have a json object like thies {"test" : "test"}, but if I convert it to a SwfiftyJSON.JSON object, and then I fetch the rawstring by function rawString(), then I convert the rawstring to a json object, but unfortunately, I can not get the correct json object, if I try to get "test" property or any other property, it always return nil, what is wrong?

like image 618
YonF Avatar asked Oct 29 '25 00:10

YonF


1 Answers

SWIFT 5

If you want to get rid of white-spaces and new lines characters from your output, you should disable pretty Printing.

You can achieve this by

let myString = yourJsonObject.rawString(String.Encoding.utf8, options: JSONSerialization.WritingOptions.init(rawValue: 0))

Old versions

let myString = yourJsonObject.rawString(NSUTF8StringEncoding, options: NSJSONWritingOptions(rawValue: 0))
like image 159
korgx9 Avatar answered Nov 01 '25 08:11

korgx9