views:

122

answers:

1

My JSON that is being returned from my ASP.NET MVC application looks like this:

{code: "1", error: "0", output: "<div class="a1"><div class="b1">this is fasta's</div></div>}

It is not working because I am not escaping it properly.

I'm not using a JSON library, can someone recommend a function that would clean up my HTML so this works?

I tried escaping for \ but it still doesn't work.

If I HTML encode it, should it work fine?

There will be user generated content so this has to work for all potential inputs by the user.

+1  A: 

Are you able to use single quotes to wrap your HTML attribute values? I think that should work if you are able to do that.

For example,

{code: "1", error: "0", output: "<div class='a1'><div class='b1'>this is fasta's</div></div>"}

If that doesn't work, try using 2 backslashes to escape the double quotes.

For example,

{code: "1", error: "0", output: "<div class=\\"a1\\"><div class=\\"b1\\">this is fasta's</div></div>"}
T B