我有一个简单的json身体
"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"horizontal@Offset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}
所以在反序列化期间使用
xmldoc = JsonConvert.DeserializeXmlNode(jsonBody, "widget")
我收到此异常
The '@' character, hexadecimal value 0x40, cannot be included in a name.
我的问题是NewtonSoft JSON解析器有任何命名约定,因为它无法转换' @'字符?如果没有,如何摆脱这种异常?
答案 0 :(得分:0)
正如错误所述,根据W3C https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name,@在xml元素的名称中不是有效字符。您可能需要更改水平@ Offset