我正在尝试从游戏启动器的网络服务器反序列化数据
API docs以json格式提供数据,但我一直在努力读取我给出的数据并将其存储为用于登录播放器的变量。我还尝试过其他一些东西,但我现在只是被困住了。
通常服务器的响应是这样的:
response.url
反序列化数据的代码:
def parse_item(self, response):
item = MovieNotifyItem()
item['url'] = response.url # "url" field should be defined for "MovieNotifyItem" Item class
# ...
yield item
包含我想要存储的变量的类
{"success":"true","gameserver":"gameserver-alpha.toontownrewritten.com","cookie":"deadbeefdeafbeef0x123"}
我搞砸了什么想法或者应该怎么做?谢谢,本。
编辑:终于明白了,我需要将结果更改为:
Dim result() As TTRServerResponse = JsonConvert.DeserializeObject(Of TTRServerResponse())(responseFromServer)
我也回来了仅返回Public Class TTRServerResponse
Public Property success As String
Public Property eta As String
Public Property position As String
Public Property queueToken As String
Public Property cookie As String
End Class
,数据错误地显示在我的其他子上。我需要做的是返回Dim result As TTRServerResponse = JsonConvert.DeserializeObject(Of TTRServerResponse) (responseFromServer)
。我现在有了更好的理解。
答案 0 :(得分:1)
您正在尝试将JSON反序列化为数组,但在您的示例中,它是单个对象。
所以假设
Dim responseFromServer As String
等于
{"success":"true","gameserver":"gameserver-alpha.toontownrewritten.com","cookie":"deadbeefdeafbeef0x123"}
根据您链接的文档,假设它是单个对象,
然后您需要更新代码以将单个对象反序列化为数组
Dim result As TTRServerResponse = JsonConvert.DeserializeObject(Of TTRServerResponse)(responseFromServer)