Prevent JSON.NET Xml converter from prefixing attributes with '@' [duplicate]

帅比萌擦擦* 提交于 2019-12-12 18:31:35

问题


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?

来源:https://stackoverflow.com/questions/14897795/prevent-json-net-xml-converter-from-prefixing-attributes-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!