VB.Net需要一些使用JavaScriptSerializer来反序列化JSON字符串的提示

时间:2016-02-01 03:01:08

标签: json vb.net

在这里提出第一个问题,很高兴成为编码社区的一员!

目前我正在从API检索JSON字符串,响应如下:

[{"playerId":37067559,"championId":78,"championLevel":5,"championPoints":93023,"lastPlayTime":1454133232000,"championPointsSinceLastLevel":71423,"championPointsUntilNextLevel":0},{"playerId":37067559,"championId":105,"championLevel":5,"championPoints":39025,"lastPlayTime":1454130615000,"championPointsSinceLastLevel":17425,"championPointsUntilNextLevel":0},{"playerId":37067559,"championId":81,"championLevel":5,"championPoints":37068,"lastPlayTime":1454273384000,"championPointsSinceLastLevel":15468,"championPointsUntilNextLevel":0}]

我将字符串设置为“response2”

Dim response2 As String = serviceRequest.DownloadString(New Uri(Mastery))

但是在使用JavaScriptSerializer时,代码会退出我的控制台

Dim jss As New JavaScriptSerializer()
Dim model As MyModel = jss.Deserialize(Of MyModel)(response2)
Console.Write(model.championId(0))

Console.ReadLine()

我为Deserializer设置了模型

Public Class MyModel
Public Property playerId() As String
Public Property championId() As String
Public Property championPoints() As String
Public Property lastPlayTime() As String
Public Property championPointsSinceLastLevel() As String
Public Property championPointsUntilNextLevel() As String
End Class

但是在启动时,控制台会自行退出。我不确定我是否应该使用model.championId(0)以及我认为因为有多套championId。

1 个答案:

答案 0 :(得分:0)

您需要git cherry-pick -X subtree=vendor/package e064480..eab48b59c 数组来保存序列化对象

试试这个(代码注释):

MyModel