For example:
let array = ["1234","5678"]
this array of values should be converted to the following string -
"[\"1234\",\"5678\"]"
Although I found answer here - Objective-C - How to convert NSString to escaped JSON string? but it doesn't look clean. Is there some cleaner way to do this ?
I am able to get this output - "["one","two"]" using
NSJSONSerialization.dataWithJSONObject
but how to have backslashes in between of strings?
["one","two"], the"'s are characters which have been escaped (that's why they appear in the string itself, rather than delimiting separate strings). Try doingprint("[\"1234\",\"5678\"]")– you'll get an output of["one","two"]. Now try doingdebugPrint("[\"1234\",\"5678\"]")– Swift will insert backslashes into the output to show that the"characters are part of the actual string. You don't need to "add escaped characters".