Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用VB.Net解析Net.WebClient结果_Vb.net_Webclient - Fatal编程技术网

如何使用VB.Net解析Net.WebClient结果

如何使用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

结果:

{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("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