0

After help on another question I can now deserialize XML in vb.net. However I'm having an issue when it comes to an array of a class. The XML classes I use are as follows;

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

The issue is in the response class. It defines listing() as listing, which to me means it should be able to hold multiple listings, however when I deserialize it seems like all listings but the first are ignored. I deserialize using this code:

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

The above works without errors. The only problem that I can see thus far is the loss of other listings.

Here is the 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>
FraserOfSmeg
  • 1,128
  • 2
  • 23
  • 41

0 Answers0