Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey!

I hope someone of you can help me.
I am receivin JSON and therefore, I created a class.
So far so good :)

VB
Public Class HotelList

    <JsonProperty("@size")>
    Public Property Size As String

    <JsonProperty("@activePropertyCount")>
    Public Property ActivePropertyCount As String

    <JsonProperty("HotelSummary")>
    Public Property HotelSummary As List(Of HotelSummary)
End Class


Normally, "HotelSummary" is a list, but in some cases not.
How should I handle that?

Thanks in advance!!!
Cheers
Posted
Comments
DamithSL 3-Jun-14 9:01am    
what is the problem? so you have at least one item as HotelSummary?
Member 9500954 3-Jun-14 9:31am    
i am getting an error because it is not a list anymore
Member 9500954 18-Jun-14 10:27am    
Hey! Does anyone of you can help me with this? Would be awesome. Cheers

1 solution

Easiest is to simply always return an array of HotelSummary. If there is only one HotelSummary, then there is just 1 item in the array. When non are returned, it is just an empty list. This makes it a lot easier.

Good luck!
 
Share this answer
 
Comments
Member 9500954 18-Jun-14 5:37am    
Hey!

Thanks for your reply!
When I am doing like:
<jsonproperty("hotelsummary")>
Public Property HotelSummary() HotelSummary

or

<jsonproperty("hotelsummary")>
Public Property HotelSummary HotelSummary()

it is still not working!

Do you have any other suggestions?
Thanks a lot for your help and time
Cheers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900