JSON反序列化问题:VB.NET中的列表(项目) [英] JSON deserialisation problem: list (of item) in VB.NET

查看:76
本文介绍了JSON反序列化问题:VB.NET中的列表(项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。

我还有另一个JSON反序列化问题,令我感到沮丧。我之前遇到过反序列化问题(如何做我在VB.NET中反序列化多级JSON? [ ^ ]),这很快就解决了。但我按照步骤重复使用另一个JSON字符串,并且它抛出相同的错误。这是我试图反序列化的代码:

Hello.
I have yet another JSON deserialisation problem, and it's frustrating me. I have had a previous deserialisation problem (How do I deserialise "multi-level" JSON in VB.NET?[^]), and that was solved quickly. But I followed the steps to repeat that with yet another JSON string, and it's throwing the same error. Here is the code I am trying to deserialise:

{"timestamp":1470270507172,"profileId":"e7cc8ec97b294d2484843d330f136bbd","profileName":"iProgramIt","textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/f7f6f0e6a2a3d6db69a4afa9fef28ea4d56f37199277f95c1d2b5f0aaa4e2"}}}



它被卡住了类型SKIN。

这是我在VB.NET中的代码。


It gets stuck on type SKIN.
Here is MY code in VB.NET.

Public Class SKIN
       Public Property url As List(Of String)
   End Class

   Public Class CAPE
       Public Property url As List(Of String)
   End Class
   Public Class PropertyX
       Public Property name As String
       Public Property value As String
       Public Property signature As String
   End Class

   Public Class Skins_Base
       Public Property id As String
       Public Property name As String
       Public Property properties As List(Of PropertyX)
   End Class
   Public Class Textures
       Public Property SKIN As List(Of SKIN)
       Public Property CAPE As List(Of CAPE)
   End Class

   Public Class Skins
       Public Property timestamp As String
       Public Property profileId As String
       Public Property profileName As String
       Public Property isPublic As String
       Public Property textures As List(Of Textures)
   End Class

Public Function GETX(ByVal Str As String) As String
       Dim wc As New System.Net.WebClient
       Return wc.DownloadString(Str)
   End Function





反序列化(发生错误的地方):



Deserialisation (where the error occurs):

Dim SkinsBase As String = GETX("https://sessionserver.mojang.com/session/minecraft/profile/" & obj.id)
        Dim xObj = JsonConvert.DeserializeObject(Of Skins_Base)(SkinsBase)
        Dim b As Byte() = Convert.FromBase64String(xObj.properties(0).value)
        Dim bString As String = System.Text.Encoding.UTF8.GetString(b)
        Dim b64 = JsonConvert.DeserializeObject(Of Skins)(bString)
        MsgBox(b64.textures(0).SKIN(0).url(0))





提前谢谢。

-iProgramIt



我的尝试:



http://www.code project.com/Questions/1116304/How-do-I-deserialise-multi-level-JSON-in-VB-NET。现在没有解决这个问题。谷歌搜索,没有任何东西匹配这种情况。



Thank you in advance.
-iProgramIt

What I have tried:

http://www.codeproject.com/Questions/1116304/How-do-I-deserialise-multi-level-JSON-in-VB-NET. Didn't solve this issue, now. Googled and nothing matches this circumstance.

推荐答案

为什么不反序化你的json dictonary(字符串,对象),然后你的类的属性。

因为我认为对于多级json来说它不能轻易反序列化,因为你必须为你的json创建具有确切名称及其属性的类的确切结构。
why don't you deserialize your json dictonary of(string,object) and then the property of your class.
Because i think so for multi level json it can not be easily deserialize because you have to make the exact structure of class for your json with exact names and their property.


在比较您的类定义和Json文本时,我的印象是您收到了 Skins 对象 - 但是: textures property不是 List(Of Textures),而是Textures类型的单个对象。
When comparing your class definitions and the Json text, my impression is that you received a Skins object - but: the textures property is NOT a List(Of Textures), but a single object of type Textures.


这篇关于JSON反序列化问题:VB.NET中的列表(项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆