2

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

请帮助我如何使用 VB.Net 从这个 json 字符串中获取和/或评估对象。

谢谢

4

1 回答 1

0

这是一个有趣的,谢谢。

这是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
于 2010-07-15T17:27:22.657 回答