我对JSON、JSON.net等都非常陌生。在阅读了类似的问题后,我的代码仍然无法正常工作。
我的错误是什么?我忽略了什么?
为测试目的跳过“links”和“meta”类是否可能,还是必须定义每个属性?
我得到了以下REST输出:
{
"codes" : [
{
"href" : "https://www.someserver.com/form_definitions/OIlG4GxMyeh0sdrt3AYuaXbauGicW71M/field_definitions/zFEova6LiPM/codes/4Sxnr961xzM",
"rel" : "document_field_definition_code",
"title" : "TITLE 1"
},
{
"href" : "https://www.someserver.com/form_definitions/OIlG4GxMyeh0sdrt3AYuaXbauGicW71M/field_definitions/zFEova6LiPM/codes/buho0CsLc5k",
"rel" : "document_field_definition_code",
"title" : "TITLE 2"
},
{
"href" : "https://www.someserver.com/form_definitions/OIlG4GxMyeh0sdrt3AYuaXbauGicW71M/field_definitions/zFEova6LiPM/codes/RvQoykUM_Sk",
"rel" : "document_field_definition_code",
"title" : "TITLE 3"
}
],
"links" : [
{
"about" : "https://www.someserver.com/form_definitions/OIlG4GxMyeh0sdrt3AYuaXbauGicW71M/field_definitions/zFEova6LiPM/codes?about=1",
"href" : "https://www.someserver.com/form_definitions/OIlG4GxMyeh0sdrt3AYuaXbauGicW71M/field_definitions/zFEova6LiPM/codes",
"method" : "GET",
"rel" : "self",
"title" : null,
"type" : "codes"
},
{
"href" : "https://www.someserver.com/form_definitions/OIlG4GxMyeh0sdrt3AYuaXbauGicW71M/field_definitions/zFEova6LiPM/codes",
"method" : "POST",
"rel" : "codes",
"title" : "create new codes entity"
}
],
"meta" : {
"description" : null,
"last_page" : 1,
"page_offset" : 0,
"page_size" : 50,
"query-template" : "/codes{?query_search,page_offset,page_size,query_identification,embedded,properties,about}",
"total" : 6
}
}
我理解需要三个类:例如,代码、链接和元数据。
我创建了一个名为“clscodes”的类:
Public Class clsCode
Private m_href As String
Private m_rel As String
Private m_title As String
Public Property Href As String
Get
Return m_href
End Get
Set(value As String)
m_href = value
End Set
End Property
Public Property Rel As String
Get
Return m_rel
End Get
Set(value As String)
m_rel = value
End Set
End Property
Public Property Title As String
Get
Return m_title
End Get
Set(value As String)
m_title = value
End Set
End Property
End Class
我创建了一个名为clsValuelist的类:
Public Class clsWerteliste
Private m_code As IList(Of clsCode)
Public Property Code() As clsCode()
Get
Return m_code
End Get
Set(value As clsCode())
m_code = value
End Set
End Property
End Class
当我尝试反序列化时,我得到了“nothing”,就像“CoolOutput”一样。
Dim CoolOutput As New clsWerteliste
CoolOutput = JsonConvert.DeserializeObject(Of clsWerteliste)(jsonstring)