这是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 []'。
有人可以帮我正确构建我的课程吗?
答案 0 :(得分:0)
虽然我对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序列化它们时的样子。