Parsing JSON with quotation marks

Hi Guys


One of the best features in new Foundation is the Codable protocol. Parsing JSONs is much easier but I have a problem with quotation marks. Please, take a look at this JSON:


[

{

"title": "My great \"Title\""

}

]


The string at "title" key is : My great "Title".


How can it be parsed using Codable protocol ? When I remove additional quotation marks from the string, JSON is parsed correctly. If quotation marks exist, I got empty array and no error 😟


Can somebody help me?

Thanks

Marek

Post not yet marked as solved Up vote post of marx_dzida Down vote post of marx_dzida
3.2k views

Replies

sorry, I got the error: Badly formed object around character

And what is interesting, when I encode such a string (with quotation marks) using "encode" method, and then decode it, it just working ok. I'm really confused.

Your question can't be answered without knowing where the JSON data is coming from. Do you have a literal string in your code? Are you reading a file? Is it the result of a network request?


Then, what API are you using to do the decoding? There's an older NSJSONSerialization class, and a newer JSONDecoder.


Assuming you're using JSONDecoder, what is the raw data you're passing to it?

Thanks for replay. I already got the answer from the Swift Development Team.


https://bugs.swift.org/browse/SR-5552