0

So I've a problem with my code. I mean, when I am building it, console shows me an error like: "Unhandled exception. Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path 'ranked', line 1, position 11." What should I do? I will add my code down below my issue

using System.Net.Http;
using System.Threading.Tasks;

namespace WhatIsMyMMRv2
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var httpClient = HttpClientFactory.Create();
            var URL = "https://eune.whatismymmr.com/api/v1/summoner?name=Kams0n";
            HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(URL);
            if (httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var content = httpResponseMessage.Content;
                var data = await content.ReadAsAsync<Data>();
                Console.WriteLine(data);
            } else
            {
                Console.WriteLine($"Error " + httpResponseMessage.StatusCode);
            }
        }
    }
}
public class Data
{
    public string Ranked
    {
        get;
        set;
    }
    public string Normal
    {
        get;
        set;
    }
    public string Aram
    {
        get;
        set;
    }

    public override string ToString()
    {
        return $"{Ranked}, {Normal}, {Aram}";
    }
} ``
Qubix
  • 11
  • check the _actual_ data structure of the response you're getting, and compare it with _your_ data structure. (hint: `string`s are not the same as `complex objects`) – Franz Gleichmann May 24 '21 at 12:50
  • Are you able to provide us with how JSON looks like? Can we also get .NET version, you seem to be using Newtonsoft.JSON, which is not a standard library – pevecg May 24 '21 at 12:50
  • Log what is comming into httpResponseMessage.Content and show us – Augusto Ferbonink May 24 '21 at 12:55
  • Your class structure is wrong. Go to https://eune.whatismymmr.com/api/v1/summoner?name=Kams0n . Copy the contents. Go to https://app.quicktype.io/ and paste them. Use the classes it generates. – mjwills May 24 '21 at 13:13

0 Answers0