我有一个类似这样的JSON类
Namespace PaymentMethod
Public Class PaymentMethodItems
<JsonProperty("id")>
Public Property Id As Integer
<JsonProperty("name")>
Public Property Name As String
<JsonProperty("description")>
Public Property Description As String
<JsonProperty("status")>
Public Property Status As Integer
End Class
Public Class Data
<JsonProperty("payment_method")>
Public Property PaymentMethod As PaymentMethodItems()
End Class
Public Class PaymentMethod
<JsonProperty("event_name")>
Public Property Event_Name As String
<JsonProperty("data")>
Public Property Data As Data
End Class
End Namespace
当我想序列化这个JSON对象时,我会使用像这样的
For Each dr In _dtDelete.Rows
row = New JSON.PaymentMethod.PaymentMethodItems
Try
row.Id = dr("id")
row.Name = dr("name") ' This one comment
row.Description = dr("opis") ' This one comment
row.Status = dr("Skriven") ' This one comment
rows.Add(row)
Catch ex As Exception
End Try
Next
tableData = New JSON.PaymentMethod.Data With {.PaymentMethod = rows.ToArray()}
Dim data As New JSON.PaymentMethod.PaymentMethod
data = New JSON.PaymentMethod.PaymentMethod With {.Data = tableData, .Event_Name = "payment_method_delete"}
我想知道是否有任何方法可以序列化这个对象,我的意思是json将只在项目列表中输出ID作为输出。我不需要输出中的所有这些属性我只需要ID。
我评论了上面写的那些行,但它仍然为我创建了一个对其他属性为空值的对象。
我想我需要改变这一行
tableData = New JSON.PaymentMethod.Data With {.PaymentMethod = rows.ToArray()}
而不是rows.ToArray我需要以某种方式只告诉那些行中的ID。