[英]Deserializing json with nested dictionary
I've gotten pretty far but ran into wall with this. 我走的很远,但是碰到了这个。 Have JSON coming from a web API I am using.
JSON来自我正在使用的Web API。
Here is the Json string (or at least the first part) 这是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": [ ]
},
My two classes: 我的两个班:
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
Main code deserliazing the json: 主要代码反序列化json:
json_in = File.ReadAllText(Path.GetTempPath() & "\hvac.json")
Dim hvac = JsonConvert.DeserializeObject(Of HVAC)(json_in)
If I comment out the "response" property I deserialize without any errors and see all info (except in the "response" section). 如果我注释掉“响应”属性,则我将进行反序列化而没有任何错误,并查看所有信息(“响应”部分中除外)。
Cannot figure out how to get the dictionary information out. 无法弄清楚如何获取字典信息。 Think I might have to deserialize that within the hvac_item class but not sure.
想想我可能必须在hvac_item类中反序列化它,但不确定。
Any help would be greatly appreciated. 任何帮助将不胜感激。
These are my best guess at the classes I get from the incomplete JSON fragment provided... 这些是我从提供的不完整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
And to access the data.... 并访问数据。
Dim HVAC = Newtonsoft.Json.JsonConvert.DeserializeObject(Of HVAC)(IO.File.ReadAllText("\HVAC.json"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.