Question

{"images":[{"id":"obj_0","src":"background.jpg","width":"640","height":"480"},{"id":"obj_9","src":"elements/pipe.png","width":50,"height":44,"top":196,"left":154,"rotation":"0"},{"id":"obj_13","src":"elements/cigarette.png","width":45,"height":67,"top":168,"left":278,"rotation":"0"},{"id":"obj_10","src":"elements/hat.png","width":227,"height":122,"top":28,"left":241,"rotation":"0"},{"id":"obj_14","src":"elements/hair.png","width":244,"height":204,"top":-17,"left":98,"rotation":"0"}]}

please help me how to get and/or evaluate object from this json string with VB.Net.

thanks

Was it helpful?

Solution

This was a fun one, thank you.

Here is the answer in VB.

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
    Dim json = litData.Text 'or put your json string in here {"images":[{"id"...}]} etc.'

    Dim ser As New Web.Script.Serialization.JavaScriptSerializer
    Dim images = ser.Deserialize(Of jsonImageArray)(json)

    'Now do something with your deserialized data.'
End Sub

'for {"images" collection'
Public Class jsonImageArray
    Public images As jsonImage()
End Class

'for sub elements'
Public Class jsonImage
    Public id As String
    Public src As String
    Public width As Int32
    Public height As Int32
    Public top As Int32
    Public left As Int32
    Public rotation As Double
End Class
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top