1

I have a JSON string which contains an escaped Unicode character. The JSON includes this snippet:

I co-ordinate our Chat Literacy network \u2013 an online group for practitioners of Information Literacy

The \u2013 is a long dash.

I'm using

var theObject = eval ("(" + jsonString + ")");

to convert the JSON string to a JavaScript object. I need to use a version of SpiderMonkey that doesn't have a direct JSON to Object method in it.

After conversion, the character in question becomes the Unicode control character \0013 which is an invalid UTF-8 character.

Is there another way I can convert the JSON to an object which will preserve the correct long-dash character? Maybe some other JSON to Object method I can load?

This happens with some other characters also, like curly quotes.

Thanks,

Doug

1
  • 1
    Does anyone know if the JSON.parse method in JSON 3 would solve the problem of the escaped Unicode entities? Or if there is a way of avoiding the problem with the eval() method I'm using? Commented Apr 9, 2015 at 8:02

1 Answer 1

2

eval() is evil. Stay away from it. Try using JSON 3: http://bestiejs.github.io/json3/

Sign up to request clarification or add additional context in comments.

4 Comments

Ooo, there's JSON3? I'm not keeping up :O
You know Javascript! :D For everything new there's something newer! :D
By the time you finish reading this somebody is already working on JSON 4 ;)
Would the JSON.parse method in JSON 3 help with the problem I mentioned involving escaped Unicode entities?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.