views:

291

answers:

3

Hi,

I am generating my JSON manually, and I even escaped for quotes with a preceding backslash. It is causing me problems.

My HTML returned looks something like:

<div class="blah"><div class="a2">This is just a test!  I hope this work's man!</div></div>


string json = "MY HTML HERE";
json = json.Replace(@"""", @"\""");

Is there more to replace than just the double quotes?

A: 

I think is this:

json = json.Replace("\"", "\\"");

Please post more details, where is this code?

Fujiy
Shouldn't it be json.Replace("\"", "\\\"")?
rmarimon
A: 

Yes. According to the JSON spec a valid string value is 'any Unicode character except " or \ or a control-character.

jason
what is a control character?
mrblah
A: 

Do you have line breaks in the strings for the json? Sometimes this breaks up many browsers. I usually change " to \", \ to \, and cr/lf to \n. The line break is not part of the json specification as per json.org but most javascript interpreters can deal with it.

rmarimon