Im responding this to a Jquery Ajax call and it works well:
var jSonTestResultReport =@"{ ""html"" : ""I am text!"" }";
The Javascript receives it and takes the text and presents it in a Div, i can see it saying "I am Text".
But when i try to do this:
var jSonTestResultReport =@"{ ""html"" : ""<li style=""color:green;"">I am text</li>"" }";
i get the error of
unexpected token c.
How can send html by Json?
var jSonTestResultReport =@"{ ""html"" : ""<li style=""color:green;"">I am text</li>"" }";
will create a json string as
{ "html" : "<li style="color:green;">I am text</li>" }
which is not valid. unexpected token c. comes from the first letter of color.
Use a real json parser instead of forming json manually.
var json = JsonConvert.SerializeObject(new { html=@"<li style=""color:green;"">I am text</li>" });
PS: var jSonTestResultReport =@"{ ""html"" : "I am text!" }"; is not compilable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With