Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,
I am trying to deserialise some JSON in Visual Basic.
However, I am having a bit of trouble. I am using Newtonsoft.Json.
But I seem to keep getting this error when I try to deserialise some JSON:
The JSON text:
{"id":"e7cc8ec97b294d2484843d330f136bbd","name":"iProgramIt","properties":[{"name":"textures","value":"eyJ0aW1lc3RhbXAiOjE0NzAyMDkwOTIzNzQsInByb2ZpbGVJZCI6ImU3Y2M4ZWM5N2IyOTRkMjQ4NDg0M2QzMzBmMTM2YmJkIiwicHJvZmlsZU5hbWUiOiJpUHJvZ3JhbUl0IiwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2Y3ZjZmMGU2YTJhM2Q2ZGI2OWE0YWZhOWZlZjI4ZWE0ZDU2ZjM3MTk5Mjc3Zjk1YzFkMmI1ZjBhYWE0ZTIifX19"}]}


The Error when I'm trying to deserialise it:
Newtonsoft.Json.JsonSerializationException was unhandled
  HResult=-2146233088
  Message=Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Minecraft_Report_Generator.Form1+PropertyX' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.


The following is my code:
VB
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 PropertyX
    End Class

    Public Class UUID_basic
        Public Property id As String
        Public Property name As String
        Public Property legacy As Boolean
        Public Property demo As Boolean
    End Class

Dim retrieveString As String = GETX(Basic_USER & TextBox1.Text)
        Dim obj = JsonConvert.DeserializeObject(Of UUID_basic)(retrieveString)
        Dim SkinsBase As String = GETX("https://sessionserver.mojang.com/session/minecraft/profile/" & obj.id)
        Dim xObj = JsonConvert.DeserializeObject(Of Skins_Base)(SkinsBase)


The last line of that code is the one that is errored. Also, I have extracted the bits and pieces from my code relevant to this circumstance, so I realise that you cannot call functions, etc. from the class.

Thanks in advance,
-iProgramIt

What I have tried:

I have tried googling on the internet, but have found nothing matching my circumstance. I have tried looking through forums like this one, and several others. I have found nothing.
Posted
Updated 2-Aug-16 22:03pm

1 solution

In the JSON "properties" is an array (the square brackets indicate an array), even if there is only one item in the array. So your properties field needs to be a list of PropertyX. Don't know vb.net I'm afraid but I believe it's something like "as List Of PropertyX" rather than just "as PropertyX"
 
Share this answer
 
v2
Comments
iProgramIt 3-Aug-16 5:04am    
You are the best! Thank you! Btw, if you care, it is "As List(Of PropertyX)". Thanks again!

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