在vb.net

时间:2018-03-19 20:48:37

标签: xml vb.net deserialization

another question的帮助之后,我现在可以在vb.net中反序列化XML。但是,当涉及到一个类的数组时,我遇到了问题。我使用的XML类如下;

Public Class rootobject
    Public Property response As response
End Class

Public Class response
    Public Property area_name As String
    Public Property bounding_box As bounding_Box
    Public Property country As String
    Public Property county As String
    Public Property latitude As String
    Public Property listing() As listing
    Public Property longitude As String
    Public Property postcode As String
    Public Property result_count As String
End Class

Public Class bounding_Box
    Public Property latitude_max As String
    Public Property latitude_min As String
    Public Property longitude_max As String
    Public Property longitude_min As String
End Class

Public Class listing
    Public Property agent_address As String
    Public Property agent_logo As String
    Public Property agent_name As String
    Public Property agent_phone As String
    Public Property category As String
    Public Property country As String
    Public Property country_code As String
    Public Property county As String
    Public Property description As String
    Public Property details_url As String
    Public Property displayable_address As String
    Public Property first_published_date As String
    Public Property image_150_113_url As String
    Public Property image_354_255_url As String
    Public Property image_50_38_url As String
    Public Property image_645_430_url As String
    Public Property image_80_60_url As String
    Public Property image_url As String
    Public Property last_published_date As String
    Public Property latitude As String
    Public Property listing_id As String
    Public Property listing_status As String
    Public Property location_is_approximate As String
    Public Property longitude As String
    Public Property num_bathrooms As String
    Public Property num_bedrooms As String
    Public Property num_floors As String
    Public Property num_recepts As String
    Public Property outcode As String
    Public Property post_town As String
    Public Property price As String
    Public Property price_change As Object
    Public Property price_change_summary As price_Change_Summary
    Public Property property_report_url As String
    Public Property property_type As String
    Public Property short_description As String
    Public Property status As String
    Public Property street_name As String
    Public Property thumbnail_url As String
    Public Property floor_plan As Object
    Public Property image_caption As String
    Public Property letting_fees As String
    Public Property price_modifier As String
    Public Property new_home As String
End Class

Public Class price_Change_Summary
    Public Property direction As String
    Public Property last_updated_date As String
    Public Property percent As String
End Class

问题出在响应类中。它将listing()定义为列表,这对我来说意味着它应该能够容纳多个列表,但是当我反序列化时,似乎所有列表都会被忽略。我使用此代码反序列化:

 Dim serializer As New XmlSerializer(GetType(Response))
 Using reader As New FileStream(filename, FileMode.Open)
       respo = CType(serializer.Deserialize(reader), Response)
 End Using

以上工作没有错误。到目前为止,我能看到的唯一问题是丢失了其他列表。

这是xml:

<response>
<area_name>WA9</area_name>
<bounding_box>
<latitude_max>53.5027143349844</latitude_max>
<latitude_min>53.3581436650156</latitude_min>
<longitude_max>-2.64140084726415</longitude_max>
<longitude_min>-2.88405115273585</longitude_min>
</bounding_box>
<country>England</country>
<county>Merseyside</county>
<latitude>53.430429</latitude>
<listing>...</listing>
<listing>...</listing>
<listing>...</listing>
<listing>...</listing>
<listing>...</listing>
<listing>...</listing>
<listing>...</listing>
<listing>...</listing>
<listing>...</listing>
<listing>...</listing>
<longitude>-2.762726</longitude>
<postcode>WA9 5JT</postcode>
<radius>5</radius>
<result_count>1946</result_count>
<street/>
<town/>
</response>

0 个答案:

没有答案