JSON Deserialization in asp.net VB

Posted on 2008-11-07
Medium Priority
Last Modified: 2012-05-05
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

Question by:apocalypse910
  • 2

Accepted Solution

moseack earned 2000 total points
ID: 22911441
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

ID: 22915111
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!

Expert Comment

ID: 22915420
Always happy to assist.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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