【发布时间】:2017-03-31 09:55:56
【问题描述】:
我有一个简单的 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 解析器是否有任何命名约定,因为它无法转换“@”字符?如果没有,如何摆脱这个异常?
【问题讨论】:
-
那个“@”根本不构成一个有效的 XML 名称。看起来this 可以解决您的问题。