如何使用VB.Net解析Net.WebClient结果
结果: {ip:184.23.135.130,主机名: 184-23-135-130.专用静态声波网络,国家/地区代码: 美国,国家名称:美国如何使用VB.Net解析Net.WebClient结果,vb.net,webclient,Vb.net,Webclient,结果: {ip:184.23.135.130,主机名: 184-23-135-130.专用静态声波网络,国家/地区代码: 美国,国家名称:美国 我想找人帮忙,我想出来了。我包括了Json.net引用 Using client As New Net.WebClient Dim reqparm As New Specialized.NameValueCollection 'reqparm.Add("param1", "somevalue") 'reqparm.Add("par
我想找人帮忙,我想出来了。我包括了Json.net引用
Using client As New Net.WebClient
Dim reqparm As New Specialized.NameValueCollection
'reqparm.Add("param1", "somevalue")
'reqparm.Add("param2", "othervalue")
Dim responsebytes = client.UploadValues("http://ip2country.sourceforge.net/ip2c.php?format=JSON", "POST", reqparm)
Dim responsebody = (New Text.UTF8Encoding).GetString(responsebytes)
End Using
结果是一个JSON字符串。您可以使用许多JSON库中的任何一个来读取它。例如,JSON.NET。
Imports Newtonsoft.Json.Linq
Imports System.Net
Using client As New Net.WebClient
Dim reqparm As New Specialized.NameValueCollection
'reqparm.Add("param1", "somevalue")
'reqparm.Add("param2", "othervalue")
Dim responsebytes = client.UploadValues("http://ip2country.sourceforge.net/ip2c.php?format=JSON", "POST", reqparm)
Dim responsebody = (New Text.UTF8Encoding).GetString(responsebytes)
Dim blah As String = client.DownloadString("http://ip2country.sourceforge.net/ip2c.php?format=JSON")
Dim json As JObject = JObject.Parse(responsebody)
Console.WriteLine(json.SelectToken("ip"))
Console.WriteLine(json.SelectToken("hostname"))
Console.WriteLine(json.SelectToken("country_code"))
Console.WriteLine(json.SelectToken("country_name"))
Console.ReadKey()
End Using