我正在尝试为 Windows 通用应用程序做概念验证,调用和显示 Riot API 数据。id喜欢输入一个名字,点击提交然后结果显示在下面。
**问题:**解析值时遇到意外字符:h。路径 '',第 0 行,第 0 位置
AND:此异步方法缺少“等待”运算符,将同步运行。考虑使用'await'操作符来等待非阻塞API调用,或者'await Task.Run
代码: 公共密封部分类 MainPage :Page {
public MainPage()
{
this.InitializeComponent();
}
private void inputButton_Click(object sender, RoutedEventArgs e)
{
GetSumInfo(nameInput.Text).Wait();
}
private void nameInput_TextChanged(object sender, TextChangedEventArgs e)
{
}
public async Task GetSumInfo(string nameInput)
{
using (var handler = new HttpClientHandler())
using (var client = new System.Net.Http.HttpClient(handler))
{
var RitoKey = "FakeKEY";
var iwantthisplayer = nameInput;
client.BaseAddress = new Uri("https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var CompleteUrl = ("https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/" + iwantthisplayer + "?api_key=" + RitoKey);
//var response = await client.GetAsync(CompleteUrl);
TbOutput.Text = JsonConvert.DeserializeObject<dynamic>(CompleteUrl);
//TbOutput.Text = JsonConvert.DeserializeObject<dynamic>(jsoncall);
//TbOutput.Text = source;
}
}
private void TbOutput_SelectionChanged(object sender, RoutedEventArgs e)
{
}
}