JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.64k stars 3.24k forks source link

Problem with Deserialize number like 0...8 and 0...9 #2970

Closed DSW-DWA closed 1 week ago

DSW-DWA commented 1 week ago

Source/destination types

public class Root
{
    public int id { get; set; }
}

Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);

Source/destination JSON

{
        "id": 08
}

Expected behavior

// Outputs to the console 8
Console.WriteLine(myDeserializedClass.id)

Actual behavior

Exception: Input string '08' is not a valid number. Path 'id', line 1, position 17.

Steps to reproduce

Newtonsoft.Json version 10.0.3

using Newtonsoft.Json;

void Main() 
{
    var myJsonResponse = "{\"id\":08}";
    Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
}

public class Root
{
    public int id { get; set; }
}
bartelink commented 1 week ago

See also #2035 (TL;DR technicaly this is not a bug, and this library is in a very low touch maintenance phase so all bets are off in terms of the library having an in-the-box answer for your problem)

DSW-DWA commented 1 week ago

Thanks