I want to serialize Dictionary<string, object>
and keep type information of object
. But Json.Net not work as expected.
var d = new Dictionary<string, object>();
d["A"] = 1;
d["B"] = (Int16)2;
d["C"] = (byte)3;
d["D"] = SomeEnum.EnumValue;
d["E"] = true;
d["F"] = "string";
WriteToFile("xxx.json" JsonConvert.SerializeObject(d));
d = JsonConvert.DeserializeObject<string, object>(ReadFromFile("xxx.json"));
// d["A"] is long (Int64), expect Int32
// d["B"] is long (Int64), expect Int16
// d["C"] is long (Int64), expect byte
// d["D"] is long (Int64), expect SomeEnum.EnumValue
How to deserialize to the origin type ?