Visual Studio 2013 vb 怎么处理JSON数据
现在我需要处理一段从网页接收到JSON数据,但不知怎么从这段JSON格式的数据中分离出我想要的数据,请赐教。
我用的语言是Visual Studio 2013 vb 。
请尽量详细一点,谢谢。
[解决办法]
引入命名空间:Newtonsoft.Json;没有去下一个Newtonsoft.Json.Net35.dll
如:网页返回格式: string data="{'a':'aaa','b':'bbb','c':'ccc'}";
Private Function GetJson() As String
Dim getUrl As String = "http://www......."
Dim webReq As WebRequest = WebRequest.Create(getUrl)
Dim webResp As WebResponse = webReq.GetResponse()
Dim stream As Stream = webResp.GetResponseStream()
Dim sr As New StreamReader(stream, Encoding.UTF8)
Dim html As String = sr.ReadToEnd()
sr.Close()
stream.Close()
Return html
End Function
'调用
Dim json As String = GetJson()
Dim jo As JObject = JObject.Parse(json)
'string a1 = jo["a"].ToString();这也可以
'string a2 = jo["b"].ToString();
'string a3 = jo["c"].ToString();
Dim values As String() = jo.Properties().[Select](Function(item) item.Value.ToString()).ToArray()
Dim a1 As String = values(0).ToString() & " " & values(1).ToString() & " " & values(2).ToString()