3

I use Json.net to parse json responce from web, but i have a problem if the json response contain html code.

For example:

string hj = @"{""data"": ""<a href=""www.google.com"">Google</a>""}";
JObject o1 = JObject.Parse(hj);

It raise a exception.

How can I parse the JSon response?

1
  • Actually this is not valid json. That's why you get an error. href=""www.google.com"" part is breaking it. Commented Jan 17, 2013 at 10:46

2 Answers 2

2

The JSON is invalid, so it can't be parsed. You have to escape the quotation marks inside the string:

string hj = @"{""data"": ""<a href=\""www.google.com\"">Google</a>""}";
Sign up to request clarification or add additional context in comments.

Comments

0

Try to encode HTML code with System.Web.HttpUtility.HtmlEncode() method

Comments

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.