C# JSON反序列化-int自动转换为long

C# JSON反序列化-int自动转换为long,c#,json,json.net,C#,Json,Json.net,如果我将一些JSON反序列化到对象字典中,如下所示: var properties = "{\"property1\":\"\",\"property2\":2}"; var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(properties); Console.WriteLine(dictionary["property2"].GetType()); // Prints

如果我将一些JSON反序列化到对象字典中,如下所示:

var properties = "{\"property1\":\"\",\"property2\":2}";

var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(properties);

Console.WriteLine(dictionary["property2"].GetType()); // Prints System.Int64
var properties=“{\”property1\“:\”,\“property2\”:2}”;
var dictionary=JsonConvert.DeserializeObject(属性);
Console.WriteLine(字典[“property2”].GetType());//打印System.Int64
整数值属性
property2
将自动反序列化为
long
而不是
int


我是否可以自动转换为
int

这显然是预期的功能。当您反序列化到
对象
时,Json.NET将选择适当的具体数据类型;对于整数值,它无条件地选择
long
。如果您不喜欢,请参见例如或。事实上,这可能是这两个属性的重复,agree?
var properties=“{\'property1\':\”,\'property2\':2}”;var t=JsonConvert.DeserializeObject(属性);Console.WriteLine(string.Join(“,t.ToList().Select(kvp=>kvp.Value?.GetType())运行那个。。。