0
votes

I am trying to do a proof of concept for a windows universal app, calling and displaying Riot API data. id like to enter a name, click submit then results displayed below.

**Issues:**Unexpected character encountered while parsing value: h. Path '', line 0, position 0

AND: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run

Code: public sealed partial class 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)
    {

    }
}
1

1 Answers

0
votes

For this part of question [AND: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run] my answer is to change this part of code :

async private void inputButton_Click(object sender, RoutedEventArgs e)

    {
        await GetSumInfo(nameInput.Text);
    }