2

Using:

let data = try! post.jsonData()
let dict = try! JSONSerialization.jsonObject(with: data, options: []) as! [String:Any]

(force unwrapping for the sake of simplicity)

I receive this:

{
  "message" : "Some message",
  "media" : [
    {
      "type" : "jpeg",
      "url" : "storage\/thumb_QEHzApawkkMq3N2IYFhwLRUxhHlJd3rJK1NyCqvB.jpeg"
    }
  ]
}

instead of this ( note the backslash for the media.url )

{
  "message" : "Some message",
  "media" : [
    {
      "type" : "jpeg",
      "url" : "storage/thumb_QEHzApawkkMq3N2IYFhwLRUxhHlJd3rJK1NyCqvB.jpeg"
    }
  ]
}

I expect to get the JSON formatted the way the object is, without that annoying backslash as the API will not accept it,

What can it be?

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Adrian
  • 415
  • 4
  • 18
  • dupe of: https://stackoverflow.com/questions/47076329/swift-string-escaping-when-serializing-to-json-using-codable – Adrian Nov 12 '19 at 09:21

1 Answers1

1

From json.org:

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

JSON String

You can also red this: https://stackoverflow.com/a/27516892/614065

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112