直接上代码
private void chaxunbutton1_Click(object sender, RoutedEventArgs e)
{
string s =textBox1.Text;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://300report.jumpw.com/api/getrole?name=" + HttpUtility.UrlEncode(s));
request.Method = "GET";
HttpWebResponse response = request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string jsonstr = sr.ReadLine();
JObject jo = (JObject)JsonConvert.DeserializeObject(jsonstr);
if (jo["Result"].ToString() == "OK")
{
textBlock1.Text=("角色名称:" + jo["Role"]["RoleName"].ToString());
textBlock2.Text = ("角色等级:" + jo["Role"]["RoleLevel"].ToString());
textBlock3.Text = ("节操值:" + jo["Role"]["JumpValue"].ToString());
textBlock4.Text = ("胜场数:" + jo["Role"]["WinCount"].ToString());
textBlock5.Text = ("总场数:" + jo["Role"]["MatchCount"].ToString());
}
else
{
textBlock3.Text = ("读取英雄信息失败!");
}
}
}
}
求大神把他改成异步调用