JSON encoding problem ":" " ' "

E

eggie5

I am sending and receiving data from my client/server using the JSON
format. However, it turns out, a lot of the time, that data has ":" or
" ' " characters in it, which causes the the javascript eval function
to throw an exception. What's the best way to handle this problem, but
still allow the ":" and " ' " characters to appear on the rendered
page?

Should I run a regex replace on ":" " ' " characters and replace them
with their escaped variants?
 
M

Matt Kruse

I am sending and receiving data from my client/server using the JSON
format. However, it turns out, a lot of the time, that data has ":" or
" ' " characters in it, which causes the the javascript eval function
to throw an exception.

it shouldn't, if you are quoting your keys and values properly.
What's the best way to handle this problem, but
still allow the ":" and " ' " characters to appear on the rendered
page?

Quote your values, and escape troublesome characters.
See the "string" diagram at http://json.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top