Click here to Skip to main content
16,020,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"}}}

It gets stuck on type SKIN.
Here is MY code in VB.NET.
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):
VB.NET
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))


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.
Posted
Updated 3-Aug-16 21:56pm
Comments
Afzaal Ahmad Zeeshan 3-Aug-16 21:49pm    
Because nothing will match you needs. In JSON, { } mean an object. Your JSON document is based on an object,
{ "timestamp": 1470270507172, ... }
To deserialize the object, you need to deserialize it to an object, not an array of objects. Secondly, your JSON and the objects are not similar. They are very hard to track and the library won't be able to understand on itself, as to map which one to which. Read this article of mine to learn more about it, From zero to hero in JSON with C#.
iProgramIt 3-Aug-16 22:11pm    
What would you suggest I do - to fix it, that is?
Afzaal Ahmad Zeeshan 3-Aug-16 22:16pm    
Please read my article, there is a guide in it. The problem is your type cannot be mapped, because of the mismatch in the names.

Change their names in JSON, if you cannot change the JSON schema, then please change the definition of your type.
iProgramIt 3-Aug-16 22:52pm    
I cannot change the names. But [forgive me for being a noob], how do I change the definition of the type? Can you guide me as to which ones to change, etc.?
Afzaal Ahmad Zeeshan 4-Aug-16 0:32am    
Change the names of the properties of your Skins_Base type.

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.
 
Share this answer
 
Comments
iProgramIt 4-Aug-16 5:58am    
It is the exact structure. And I have deserialised Multi-Level JSON. This time, it seems I have a problem that I cannot solve by using the same solution. Please see http://www.codeproject.com/Questions/1116304/How-do-I-deserialise-multi-level-JSON-in-VB-NET
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.
 
Share this answer
 
Comments
iProgramIt 4-Aug-16 5:57am    
I am still receiving the same issue as before.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900