Monday, 8 December 2014

Special char options for Newtonsoft.Json.JsonConvert.SerializeXmlNode



I have a large xml that needs to be imported into json.


My xml looks like this



<ThingsToDo>
<DoYourThing attributeType="bool">TRUE</DoYourThing>
</ThingsToDo>


When I convert this to json using the following...



string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(myXmlDoc, omitRootObject:true);


I end up with json like this



{
"DoYourThing": {
"@attributeType": "bool",
"#text": "TRUE"
}
}


The problem is the '@' and '#' have special meanings to the portions of code using the json, and the actual xml data that I am using has many @'s and #'s so I cannot use a string replace.


Is there anyway to make JsonConvert use different special chars?


Thanks a million!


No comments:

Post a Comment