[英]Issue with JSON Deserialization and VB.NET
我正在尝试使用VB.net反序列化JSON字符串,并且似乎无法将值从完成的List中拉出。 这是简单的类:
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
然后在Page_Load中插入以下内容:
Dim JSONstring As String = "[{""Name"":""John"",""Picture"":""mypic.jpg""}]"
Dim json As New JavaScriptSerializer()
Dim outputinfo = json.Deserialize(Of List(Of Personinformation))(JSONstring)
现在我迷路了,因为我似乎无法获得名称/值对。 我尝试这样做
Response.Write(outputinfo.Item(1))
有人告诉我“索引超出范围。必须为非负数并且小于集合的大小。”
我究竟做错了什么??
您的JSON数组中只有一项,但是您正在访问基于0的列表的第二项。
Response.Write(outputinfo.Item(0))
应该为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.