JSON Deserialization in VB

Posted on 2008-11-07
Last Modified: 2012-05-05
I can not seem to get  json deserialization to work correctly in 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

Question by:apocalypse910
    LVL 7

    Accepted Solution

    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.

    Author Comment

    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!
    LVL 7

    Expert Comment

    Always happy to assist.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now