[英]Deserialize JSON with vb.net
這是我手動創建的課程
Public Class ZohoList
Public Property Select_Store() As String
Get
Return m_Select_Store
End Get
Set
m_Select_Store = Value
End Set
End Property
Private m_Select_Store As String
End Class
Public Class RootObject
Public Property Zoho_List As List(Of ZohoList)
Get
Return m_Zoho_List
End Get
Set
m_Zoho_List = Value
End Set
End Property
Private m_Zoho_List As List(Of ZohoList)
End Class
我得到這樣的JSON響應后
{
"Store_Money_Snapshot":[
{
"TODO":"YES",
"Date_field":"10-May-2018",
"Xpawn_Money":"3562",
"Select_Store":"TEST",
"Total_Counted_Money":"$ 3,000.00",
"Store_from_Xpawn_pc2":"TEST",
"Discrepancy_Amount":"$ -562.00",
"Store_Problem_fixed":"NO",
"ID":"1111111111111111111",
"Image":"",
"Store_Closing_Balance":"$ 33,482.00"
},
{
"TODO":"YES",
"Date_field":"10-May-2018",
"Xpawn_Money":"10234",
"Select_Store":"TEST2",
"Total_Counted_Money":"$ 9,800.00",
"Store_from_Xpawn_pc2":"TEST2",
"Discrepancy_Amount":"$ -434.00",
"Store_Problem_fixed":"NO",
"ID":"2222222222222",
"Image":"",
"Store_Closing_Balance":"$ 33,482.00"
}
]
}
我的vb.net代碼用於反序列化對象放在兩行中
Dim myO = JsonConvert.DeserializeObject(Of RootObject)(response)
Dim items = myO.Zoho_List
For Each item In items
lTodo.Add(item.Select_Store.ToString)
'Now comes th code
Next
從整個響應中,我只需要Select_Store值,所以在類中,我只放置了該值
我也嘗試將所有值放在我的課程中,但仍然不會反序列化JSON響應
您的RootObject
與第一個大括號{
配對。
然后在json中的“根對象”上有一個屬性: Store_Money_Snapshot
,它不會出現在RootObject
任何位置Store_Money_Snapshot
是一個數組或List<>
或對象。這些對象包含您的Select_Store
屬性。
因此,這樣的事情應該會讓您感動:
Public Class RootObject
' RootObject is a HORRIBLE name.
Public Property Store_Money_Snapshot As List(Of ZohoList)
End Class
Public Class ZohoList
' Again, ZohoList is a HORRIBLE name.
Public Property Select_Store As String
End Class
我強烈建議您考慮使用更准確的描述性名稱來命名您的班級。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.