xml to json escaping

Aug 13, 2009 at 5:00 PM

Hello,

I have a case when I need to convert xml to json, but getting double encoding and because of that invalid json. Am I doing something wrong?

Here is what I do:

 

 XmlDocument doc = new XmlDocument();

 doc.LoadXml(@"<name>O""Connor</name>"); // i use "" so it will be easier to see the  problem

string xDataJson = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);

 

the string I get

"{\"name\":\"O\\\"Connor\"}"

which is not parsable by json .

 

 

 

 

 

Aug 14, 2009 at 10:46 AM

Hi,

I have the same problem. This seems to be a problem of javascriptserializer too.

 

Best wishes,

 

Christian

Coordinator
Aug 15, 2009 at 1:52 AM

I get this:

"{"name":"O\\"Connor"}"

Something else is double encoding your JSON.