我已经走得很远,但是遇到了这个问题。让JSON来自我正在使用的Web API。
这是Json字符串(或至少是第一部分)
{
"id": "065f1b17-0b2c-47c1-9674-c2bfda8c05bc",
"number": "167",
"title": "SSF-5003 MC Checklist HVAC",
"status": "open",
"description": null,
"shared": false,
"items":
[
{
"id": "a31a2f92-e948-4563-809e-6faed67e5db3",
"description": "Project Number",
"type": "text-area",
"comment": null,
"issue": null,
"response": {
"value": "Az001",
"responded_by": {
"id": "1208055465",
"organization": {
"id": "1207960635",
"name": "xxxxxxxxx",
"trading_name": "xxxx"
},
"first_name": "Brett",
"last_name": "VanDyke"
},
"responded_at": "2017-03-02T14:45:47.924Z"
},
"item_number": "1",
"photo_url": null,
"response_options": [ ]
},
我的两个课程:
Public Class HVAC
Public Property id As String
Public Property number As Int64
Public Property title As String
Public Property status As String
Public Property description As String
Public Property items As hvac_item()
End Class
Public Class hvac_item
Public Property id As String
Public Property description As String
Public Property type As String
Public Property item_number As Int32
Public Property response As Dictionary(Of String, String)
End Class
主要代码deserliazing json:
json_in = File.ReadAllText(Path.GetTempPath() & "\hvac.json")
Dim hvac = JsonConvert.DeserializeObject(Of HVAC)(json_in)
如果我发表评论"回复"属性我反序列化没有任何错误,并查看所有信息("响应"部分除外)。
无法弄清楚如何获取字典信息。想想我可能不得不在hvac_item类中反序列化但不确定。
非常感谢任何帮助。
答案 0 :(得分:0)
这是我对从提供的不完整JSON片段获得的类的最佳猜测...
Public Class HVAC
Public Property id As String
Public Property number As String
Public Property title As String
Public Property status As String
Public Property description As Object
Public Property _shared As Boolean
Public Property items As Item()
End Class
Public Class Item
Public Property id As String
Public Property description As String
Public Property type As String
Public Property comment As Object
Public Property issue As Object
Public Property response As Response
Public Property item_number As String
Public Property photo_url As Object
Public Property response_options As Object()
End Class
Public Class Response
Public Property value As String
Public Property responded_by As Responded_By
Public Property responded_at As Date
End Class
Public Class Responded_By
Public Property id As String
Public Property organization As Organization
Public Property first_name As String
Public Property last_name As String
End Class
Public Class Organization
Public Property id As String
Public Property name As String
Public Property trading_name As String
End Class
并访问数据....
Dim HVAC = Newtonsoft.Json.JsonConvert.DeserializeObject(Of HVAC)(IO.File.ReadAllText("\HVAC.json"))