Prevent JSON.NET Xml converter from prefixing attr

2019-07-15 13:16发布

问题:

This question already has an answer here:

  • JSON.NET and Replacing @ Sign in XML to JSON converstion 10 answers
  • JSON.net has @ in the attribute names? 1 answer

I'm trying to convert some XML data into JSON to use with KnockoutJS. After a bit of research I decided to go with JSON.NET to convert my XNode tree to a JSON String. I convert the XML tree by calling

JsonConvert.SerializeXNode(result, Newtonsoft.Json.Formatting.Indented, True)

which gives me something like

"Header": {
"@id": "3",
"@name": "General",
"Property": [
  {
    "@id": "76",
...

Trying to reference things like @name causes my KnockoutJS templates to break. I would just remove all instances of @ from the string, but it exists in the data as well.

Is there any easy way to prevent JSON.NET from putting the @ symbol on attributes?