/// <summary>
/// 获取全部信息
/// </summary>
/// <returns>一段网页代码</returns>
static Dictionary<string, object> getOutMessage()
{
WebClient client = new WebClient();
client.Encoding = System.Text.Encoding.Default;
string response = client.UploadString("http://pv.sohu.com/cityjson?ie=utf-8", "");
Dictionary<string, object> obj =null;
if(response!=null)
{
response = response.Substring(response.IndexOf("{"), (response.IndexOf("}")- response.IndexOf("{"))+1);
obj=KeyValueCombination(response);
}
return obj;
}
static Dictionary<string, object> KeyValueCombination(string str)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(str);
return json;
}
static string getOutIp()
{
Dictionary<string, object> response = getOutMessage();
if (response != null)
{
return response["cip"].ToString();
}
else
{
return null;
}
}
网友评论