Reputation: 81
I have following simple xml to json conversion code
XmlDocument xmlDocument=new XmlDocument();
xmlDocument.LoadXml("<Root><Record><Column>1</Column></Record></Root>");
string val=JsonConvert.SerializeXmlNode(xmlDocument,Formatting.None);
xml does get converted but the value contains some characters which json invalid.
value contains following
"{\"Root\":{\"Record\":{\"Column\":\"1\"}}}
I do not want those "\" characters in the converted string. Am I missing something here?
Upvotes: 1
Views: 648
Reputation: 1500225
Am I missing something here?
I suspect you're missing the fact that they're not really there :) I'm sure you're just seeing them in the debugger - which escapes things like quotes for you.
Just print the string to the console, and you'll see what you want.
(I've just tried it myself using your sample code, and it's fine.)
Upvotes: 1
Reputation: 6461
I'm not sure but just try this.. Instead of using Character's use the Predeclared Entity.
Character Predeclared Entity
& &
< <
> >
" "
' '
For example, the Record name “AT&T” should appear in the XML markup as “AT&T”: the XML parser will take care of changing “&” back to “&” automatically when the document is processed.
Anyone Correct me if I'm wrong...
Thanks.,
Upvotes: 0