110,538
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var uri = "http://ip.taobao.com/service/getIpInfo.php?ip=117.79.93.222";
var response = WebRequest.Create(uri).GetResponse() as HttpWebResponse;
var json = new StreamReader(response.GetResponseStream()).ReadToEnd();
var result = new JavaScriptSerializer().DeserializeObject(json) as Dictionary<string, object>;
var data = result["data"] as Dictionary<string, object>;
Console.WriteLine("country: " + data["country"]);
Console.WriteLine("area: " + data["area"]);
Console.WriteLine("city: " + data["city"]);
}
}
}
country: 中国
area: 华北
city: 北京市