[VB]解析JSON
線上解析JSON
將JSON解析,並存到StringBuilder
Public Sub Get_chart_data()
Dim chart_data As New StringBuilder()
Dim objWebClient As New System.Net.WebClient
Dim Url As String = "http://localhost/CoalTc/highchart_linechart.json"
Dim JsonStr As String = ""
JsonStr = Encoding.UTF8.GetString(objWebClient.DownloadData(New Uri(Url.Trim())))
Dim Obj As Newtonsoft.Json.Linq.JObject =
Newtonsoft.Json.JsonConvert.DeserializeObject(JsonStr)
'取得物件明細的方法 依據階層 Obj.item("階層1")("階層2") 以此類推
Dim j As Integer
'For j = 0 To i
For Each aa In Obj
For Each bb In aa.Value
Dim name As String = bb.Item("name").ToString
Dim type As String = bb.Item("type").ToString
Dim data() As String = {bb.Item("data").ToString}
chart_data.Append("{name: '" + name + "'")
chart_data.Append(",type: '" + type + "'")
chart_data.Append(",data: " + data(0) + "},")
Next
Next
End Sub
將JSON解析,並存到StringBuilder
Public Sub Get_chart_data()
Dim chart_data As New StringBuilder()
Dim objWebClient As New System.Net.WebClient
Dim Url As String = "http://localhost/CoalTc/highchart_linechart.json"
Dim JsonStr As String = ""
JsonStr = Encoding.UTF8.GetString(objWebClient.DownloadData(New Uri(Url.Trim())))
Dim Obj As Newtonsoft.Json.Linq.JObject =
Newtonsoft.Json.JsonConvert.DeserializeObject(JsonStr)
'取得物件明細的方法 依據階層 Obj.item("階層1")("階層2") 以此類推
Dim j As Integer
'For j = 0 To i
For Each aa In Obj
For Each bb In aa.Value
Dim name As String = bb.Item("name").ToString
Dim type As String = bb.Item("type").ToString
Dim data() As String = {bb.Item("data").ToString}
chart_data.Append("{name: '" + name + "'")
chart_data.Append(",type: '" + type + "'")
chart_data.Append(",data: " + data(0) + "},")
Next
Next
End Sub
留言
張貼留言