𝕭𝖔𝖙𝖙𝖑𝖊_𝕭𝖆𝖗𝖔𝖓
𝕭𝖔𝖙𝖙𝖑𝖊_𝕭𝖆𝖗𝖔𝖓
CC#
Created by 𝕭𝖔𝖙𝖙𝖑𝖊_𝕭𝖆𝖗𝖔𝖓 on 2/23/2024 in #help
Trying to scaffold a controller for ASP .NET api using MongoDB but get this message
No description
5 replies
CC#
Created by 𝕭𝖔𝖙𝖙𝖑𝖊_𝕭𝖆𝖗𝖔𝖓 on 3/1/2023 in #help
Newtonsoft.Json Serialization Exception
Trying to deserialize a List<Highscore> for my project and it throws this exception: Unhandled exception. Newtonsoft.Json.JsonSerializationException: Error converting value "{"Name":"Willy","Time":316}" to type 'ReactionGame.Highscore' Code (T is List<Highscore>):
public virtual async Task<T> Get<T>(string url) where T : class
{
using var client = new HttpClient();

var stringResult = await client.GetStringAsync(url);
return JsonConvert.DeserializeObject<T>(stringResult, new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore});
}
public virtual async Task<T> Get<T>(string url) where T : class
{
using var client = new HttpClient();

var stringResult = await client.GetStringAsync(url);
return JsonConvert.DeserializeObject<T>(stringResult, new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore});
}
Model:
namespace ReactionGame
{
public class Highscore
{
[JsonProperty]
public string Name { get; set; }
[JsonProperty]
public long Time { get; set; }

public override string ToString()
{
return Name + " - " + Time;
}

[JsonConstructor]
public Highscore(string name, long time)
{
Name = name;
Time = time;
}
}
}
namespace ReactionGame
{
public class Highscore
{
[JsonProperty]
public string Name { get; set; }
[JsonProperty]
public long Time { get; set; }

public override string ToString()
{
return Name + " - " + Time;
}

[JsonConstructor]
public Highscore(string name, long time)
{
Name = name;
Time = time;
}
}
}
Anyone know what might be wrong? I'm at a loss.
40 replies