序列化对象时查看它们的样子
这是JSON:
{
"status": "live",
"responses": 10,
"questions": {
"ZuGnqOpd3w": {
"title": "Sample Title",
"type": "threed-grid",
"id": "ZuGnqOpd3w",
"label": "Sample Label."
}
}
}
以及班级;
Public Class Survey
Public Property status As String
Public Property responses As Integer
Public Property questions() As jQuestion()
End Class
Public Class jQuestion
Public Property Title as String
......
End Class
当我尝试反序列化它时,我会得到以下错误:无法将JSON对象反序列化为类型"jQuestion[]"。
有人能帮我正确安排课程结构吗?
虽然我对json.net不是很熟悉,但根据您的类,json
对象的格式似乎不正确。由于Questions
是一个数组,因此json
中的值应该用方括号[]
括起来
{
"status": "live",
"responses": 10,
"questions": [
{
"title": "Sample Title",
"type": "threed-grid",
"id": "ZuGnqOpd3w",
"label": "Sample Label."
},
{
"title": "Sample Title 2",
"type": "threed-grid 2",
"id": "ZuGnqOpd3w 2",
"label": "Sample Label. 2"
}
]
}
将来,当验证您试图反序列化的json
格式时,您可以通过在.net中创建对象来作弊,然后在使用json.net.