如何遍历反序列化jason并将名称/值分配给文本框
Dim ProductDetail = serializer.Deserialize(Of List(Of ChinaVJsonDeserializer.RootObject()))(ReturnStr)
Dim Product As ChinaVJsonDeserializer.RootObject
For Each Product In ProductDetail
Dim sb As New StringBuilder
sb = sb.AppendLine("id:" & ProductDetail.product_id)
sb = sb.AppendLine("Model_Code:" & ProductDetail.model_code)
Me.txtProductDetail.Text = sb.ToString
它返回此错误 System.Web.HttpUnhandledException:抛出了类型'System.Web.HttpUnhandledException'的异常。 ---> System.MissingMemberException:未找到类型'List(Of RootObject())'上的公共成员'Product'。
示例json
{
"products": [
{
"product_id": 222,
"model_code": "xxx",
"full_product_name": "xxx",
"short_product_name": "xxx",
"product_url": "xxx",
"category_name": "xxx",
"subcategory_name": "xxx",
"subcategory_url": "xxx",
"date_product_was_launched": "xxx",
"main_picture": "xxx",
"currency": "xxx",
"price": "xx.xx",
"retail_price": "xx.xx",
"ean": "xxx",
"continuity": "xxx",
"overview": "xxx",
"specification": "xxx",
"additional_images": [
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx"
],
"related_products": [
{
"product_id": 22
},
{
"product_id": 22
},
{
"product_id": 22
},
{
"product_id": 22
},
{
"product_id": 22
},
{
"product_id": 22
}
],
"package": {
"weight_kg": 2.22,
"height_mm": 3,
"width_mm": 33,
"depth_mm": 2
},
"status": "xxx",
"meta_keyword": "xxx",
"meta_description": "xxx"
}
]
}
类
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.text
Imports System.Net
Public Class ChinaVJsonDeserializer
Public Class RelatedProduct
Public Property product_id() As Integer
Get
Return m_product_id
End Get
Set(ByVal value As Integer)
m_product_id = Value
End Set
End Property
Private m_product_id As Integer
End Class
Public Class Package
Public Property weight_kg() As Double
Get
Return m_weight_kg
End Get
Set(ByVal value As Double)
m_weight_kg = Value
End Set
End Property
Private m_weight_kg As Double
Public Property height_mm() As Integer
Get
Return m_height_mm
End Get
Set(ByVal value As Integer)
m_height_mm = Value
End Set
End Property
Private m_height_mm As Integer
Public Property width_mm() As Integer
Get
Return m_width_mm
End Get
Set(ByVal value As Integer)
m_width_mm = Value
End Set
End Property
Private m_width_mm As Integer
Public Property depth_mm() As Integer
Get
Return m_depth_mm
End Get
Set(ByVal value As Integer)
m_depth_mm = Value
End Set
End Property
Private m_depth_mm As Integer
End Class
Public Class Product
Public Property product_id() As Integer
Get
Return m_product_id
End Get
Set(ByVal value As Integer)
m_product_id = Value
End Set
End Property
Private m_product_id As Integer
Public Property model_code() As String
Get
Return m_model_code
End Get
Set(ByVal value As String)
m_model_code = Value
End Set
End Property
Private m_model_code As String
Public Property full_product_name() As String
Get
Return m_full_product_name
End Get
Set(ByVal value As String)
m_full_product_name = Value
End Set
End Property
Private m_full_product_name As String
Public Property short_product_name() As String
Get
Return m_short_product_name
End Get
Set(ByVal value As String)
m_short_product_name = Value
End Set
End Property
Private m_short_product_name As String
Public Property product_url() As String
Get
Return m_product_url
End Get
Set(ByVal value As String)
m_product_url = Value
End Set
End Property
Private m_product_url As String
Public Property category_name() As String
Get
Return m_category_name
End Get
Set(ByVal value As String)
m_category_name = Value
End Set
End Property
Private m_category_name As String
Public Property category_url() As String
Get
Return m_category_url
End Get
Set(ByVal value As String)
m_category_url = Value
End Set
End Property
Private m_category_url As String
Public Property subcategory_name() As String
Get
Return m_subcategory_name
End Get
Set(ByVal value As String)
m_subcategory_name = Value
End Set
End Property
Private m_subcategory_name As String
Public Property subcategory_url() As String
Get
Return m_subcategory_url
End Get
Set(ByVal value As String)
m_subcategory_url = Value
End Set
End Property
Private m_subcategory_url As String
Public Property date_product_was_launched() As String
Get
Return m_date_product_was_launched
End Get
Set(ByVal value As String)
m_date_product_was_launched = Value
End Set
End Property
Private m_date_product_was_launched As String
Public Property main_picture() As String
Get
Return m_main_picture
End Get
Set(ByVal value As String)
m_main_picture = Value
End Set
End Property
Private m_main_picture As String
Public Property currency() As String
Get
Return m_currency
End Get
Set(ByVal value As String)
m_currency = Value
End Set
End Property
Private m_currency As String
Public Property price() As String
Get
Return m_price
End Get
Set(ByVal value As String)
m_price = Value
End Set
End Property
Private m_price As String
Public Property retail_price() As String
Get
Return m_retail_price
End Get
Set(ByVal value As String)
m_retail_price = Value
End Set
End Property
Private m_retail_price As String
Public Property ean() As Long
Get
Return m_ean
End Get
Set(ByVal value As Long)
m_ean = Value
End Set
End Property
Private m_ean As Long
Public Property continuity() As String
Get
Return m_continuity
End Get
Set(ByVal value As String)
m_continuity = Value
End Set
End Property
Private m_continuity As String
Public Property overview() As String
Get
Return m_overview
End Get
Set(ByVal value As String)
m_overview = Value
End Set
End Property
Private m_overview As String
Public Property specification() As String
Get
Return m_specification
End Get
Set(ByVal value As String)
m_specification = Value
End Set
End Property
Private m_specification As String
Public Property additional_images() As List(Of String)
Get
Return m_additional_images
End Get
Set(ByVal value As List(Of String))
m_additional_images = Value
End Set
End Property
Private m_additional_images As List(Of String)
Public Property related_products() As List(Of RelatedProduct)
Get
Return m_related_products
End Get
Set(ByVal value As List(Of RelatedProduct))
m_related_products = Value
End Set
End Property
Private m_related_products As List(Of RelatedProduct)
Public Property package() As Package
Get
Return m_package
End Get
Set(ByVal value As Package)
m_package = Value
End Set
End Property
Private m_package As Package
Public Property status() As String
Get
Return m_status
End Get
Set(ByVal value As String)
m_status = Value
End Set
End Property
Private m_status As String
Public Property meta_keyword() As String
Get
Return m_meta_keyword
End Get
Set(ByVal value As String)
m_meta_keyword = Value
End Set
End Property
Private m_meta_keyword As String
Public Property meta_description() As String
Get
Return m_meta_description
End Get
Set(ByVal value As String)
m_meta_description = Value
End Set
End Property
Private m_meta_description As String
End Class
Public Class RootObject
Public Property products() As List(Of Product)
Get
Return m_products
End Get
Set(ByVal value As List(Of Product))
m_products = Value
End Set
End Property
Private m_products As List(Of Product)
End Class
End Class