【问题标题】:Issue with JSON Deserialization and VB.NETJSON 反序列化和 VB.NET 的问题
【发布时间】:2012-02-25 05:22:27
【问题描述】:

我正在尝试使用 VB.net 反序列化 JSON 字符串,但似乎无法从完成的列表中提取值。这是一个简单的类:

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))

我被告知“索引超出范围。必须为非负数且小于集合的大小。”

我做错了什么??

【问题讨论】:

    标签: asp.net vb.net json


    【解决方案1】:

    您的 JSON 数组中只有一项,但您正在访问基于 0 的列表的第二项。

    Response.Write(outputinfo.Item(0))
    

    应该适合你。

    【讨论】:

      猜你喜欢
      • 2011-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多