【发布时间】:2020-12-01 17:38:07
【问题描述】:
我有这种 JSON 文件:
[{
"orderId": "36186",
"customerID": "584",
"OrderArticle": [
{
"productId": "1780",
"webCategory": "Cat1",
"articleQty": "1",
"perQty": ""
},
{
"productId": "2587",
"webCategory": "Cat3",
"articleQty": "58",
"perQty": ""
}
]
//..........
}]
还有那些类:
Public Class Response
Public Property show() As Orders
End Class
Public Class Orders
Public Property productID As String
Public Property orderDate As String
Public Property articles() As New List(Of Orderarticle)
End Class
Public Class Orderarticle
Public Property productId As String
Public Property webCategory As String
Public Property articleQty As String
Public Property perQty As String
End Class
OrderArticle 可能包含 1 到 x 篇文章。
我正在尝试:
Dim json As String = My.Computer.FileSystem.ReadAllText(filePath)
Dim orderList = JsonConvert.DeserializeObject(Of List(Of Response))(json)
但是我做错了,我无法遍历每个订单中的文章列表。 是的,我已经检查了与此问题相关的所有 Q/A,问题是空引用,不确定是 JSON 格式问题、Newtonsoft 问题还是我的错。
【问题讨论】: