Brandon
Brandon

Reputation: 319

Why is my JSON returning escape code for a single quote (apostrophe)

I'm receiving JSON data from server that contains text which should have an apostrophe but instead I see the escape code for an apostrophe. Is this an issue with the way the JSON is formatted?

This is how I have it on server-side:

[{"testJ":6387,"title":"This is JSON's return",}]

This is what I'm getting back:

[{"testJ":6387,"title":"This is JSON's return",}]  

If I have not provided enough detail, please let me know and I will try to add more information.

Upvotes: 0

Views: 310

Answers (1)

agusgambina
agusgambina

Reputation: 6699

Your JSON is almost valid, but you have a problem, you have add one comma that shouldn't be there. (the last comma).

You can check this using a JSON validator site like

http://www.freeformatter.com/json-validator.html

http://jsonformatter.curiousconcept.com/

http://jsonlint.com/

On the other hand, think that the apostrophe is a way to enclose text, so what you are using to parse the JSON is what is having the problem. Try to put an escape character before the apostrophe, so should be like this on the server side

[{"testJ":6387,"title":"This is JSON\u0027s return"}]

For more information you can refer to the RFC https://www.ietf.org/rfc/rfc4627.txt and in section 2.5 you will find more information.

Upvotes: 2

Related Questions