Prevent JSON.NET Xml converter from prefixing attr

2019-07-15 13:25发布

This question already has an answer here:

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?

0条回答
登录 后发表回答