I am trying to deserialize a JSON string using VB.net and cannot seem to pull the values out of the finished List. Here is the simple class:
Public Class Personinformation
Private theName As String
Private thePic As String
Public Property Name() As String
Get
Name = theName
End Get
Set(ByVal value As String)
theName = value
End Set
End Property
Public Property Picture() As String
Get
Picture = thePic
End Get
Set(ByVal value As String)
thePic = value
End Set
End Property
End Class
Then in the Page_Load I have inserted the following:
Dim JSONstring As String = "[{""Name"":""John"",""Picture"":""mypic.jpg""}]"
Dim json As New JavaScriptSerializer()
Dim outputinfo = json.Deserialize(Of List(Of Personinformation))(JSONstring)
Now I am lost because I can’t seem to get the name/value pairs. I tried doing this
Response.Write(outputinfo.Item(1))
I am told “Index was out of range. Must be non-negative and less than the size of the collection.”
What am I doing wrong??
Your JSON array only has one item in it but you are accessing the second item of a 0 based list.
Should work for you.