我正在工作UWP (Visual Basic)我正在从一个以JSON字符串格式回复的网站获取数据。
[
{"id": 1, "name": "Johny", "lname": "Sins", "phone": 123456789},
{"id": 2, "name": "Nike", "lname": "Jons", "phone": 23456789}
]
这是我的代码是如何得到它的:-
Dim url As String = "http://127.0.0.1:8000/getdata/"
Dim Request As HttpWebRequest = HttpWebRequest.Create(url)
Request.Proxy = Nothing
Request.UserAgent = "Test"
Dim Response As HttpWebResponse = Request.GetResponse
Dim ResponseStream As System.IO.Stream = Response.GetResponseStream
Dim StreamReader As New System.IO.StreamReader(ResponseStream)
Dim Data As String = StreamReader.ReadToEnd
StreamReader.Close()
现在我想在一个文本框中一个接一个地打印这些数据,那么我如何将其转换为json数组并打印它?
我用Json数据测试了解析部分。请参考方法
Public Class node
Public Property id As Integer
Public Property name As String
Public Property lname As String
Public Property phone As Integer
End Class
Public Sub JsonTest()
Try
Dim json_test As String = "[
{'id': 1, 'name': 'Johny', 'lname': 'Sins', 'phone': 123456789},
{'id': 2, 'name': 'Nike', 'lname': 'Jons', 'phone': 23456789}
] "
Dim nodelist As List(Of node) = JsonConvert.DeserializeObject(Of List(Of node))(json_test)
For Each n In nodelist
Console.WriteLine(n.id)
Console.WriteLine(n.name)
Console.WriteLine(n.lname)
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub