【发布时间】:2017-12-26 12:38:41
【问题描述】:
我需要使用 vb.net 4.0 中的 javascriptserializer 访问嵌套的 json 对象数组中的数据,以便能够进一步操作它。
这是示例字符串:
json: {"multicast_id":216,"success":3,"failure":3,"canonical_ids":1,"results":[{"message_id":"1:0408"},{"errord":"Unavailable"}]}
这是我目前编写的代码:
Class main
Public Property multicast_id As Integer
Public Property success As Integer
Public Property failure As Integer
Public Property canonical_ids As Integer
Public Property results As Results()
End Class
Class Results
Public Property message_id As String
Public Property errord As String
End Class
Public Class Form1
Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Dim json As String
json = txtInsert.Text
Try
Dim ser As JavaScriptSerializer = New JavaScriptSerializer()
Dim exmp As main = New main
exmp = ser.Deserialize(Of main)(json)
Console.WriteLine(exmp.canonical_ids)
Console.WriteLine(exmp.multicast_id)
For Each item As Object In exmp.results
For Each example As String In item
Console.WriteLine("example")
Next
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
每个语句的内部都出现错误。如果有人能帮我解决这个问题,我将不胜感激。
【问题讨论】:
-
...错误信息是什么?请阅读How to Ask 并采取tour
标签: arrays json vb.net javascriptserializer