JSON Deserialization in asp.net VB

I can not seem to get  json deserialization to work correctly in asp.net vb
the problem seems to be in the type casting.
The JSON string represents an array of (skill_ser) which itself contains several arrays of (skill_ser)
Thank you for your help!
The data class:
<DataContract()> Class skill_ser
    <DataMember()> Public i As Integer
    <DataMember()> Public n As String
    <DataMember()> Public p As Integer
    <DataMember()> Public s() As skill_ser
    <DataMember()> Public a() As skill_ser
End Class
 
The code:
    Protected Sub writeSkills(ByVal Jskill As String)
        Dim skills As skill_ser()
        Dim stream As MemoryStream
        stream = New MemoryStream(Encoding.Unicode.GetBytes(Jskill))
        Dim JSC As DataContractJsonSerializer
        JSC = New DataContractJsonSerializer(GetType(skill_ser))
        skills = CType(JSC.ReadObject(stream), skill_ser())
        dexterity.InnerText = skills(1).p
    End Sub

Open in new window

apocalypse910Asked:
Who is Participating?
 
Refael AckermannConnect With a Mentor Commented:
I believe the problem is that your trying to cast the deserialized object to an array of skill_ser, while you create a serializer for a single skill_ser.
You could either create a deserializer for "skill_ser()", or read the objects one at time.
0
 
apocalypse910Author Commented:
Gah! - I found the problem.

I didn't realize that I had structured the data as an array of an array of skill_ser. rather than what i stated. (ah the dangers of programming while sick and half asleep.  Points awarded because you were right as well. Sorry again for the stupidity and incorrect information. Thanks again!
0
 
Refael AckermannCommented:
Always happy to assist.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.