views:

20

answers:

1

{"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

A: 

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
Carter
thanks carter!! i've tested it and it works. and yes...it was really fun. this was actually my first time asking help. all i did was search thru the net but I can say, it was good.i just have one more question, im using .net 2008 and there is a warning that javascriptserializer was already obsolete and it should be DataContractSerializer. any thoughts or perhaps, an equivalent of what you provided.again, thank you very much. :D
EkisPinoy
It is only obsolete before .net 3.5 SP1 (huh?!), so you are safe to use it. It looks like there was a large debate surrounding this. Many people were upset, so it is no longer obsolete.See this article for details...http://stackoverflow.com/questions/536359/why-microsoft-made-javascriptserializer-obsolete-prior-to-net-3-5-sp1-and-again
Carter