对元祖反序列化后结果不符合预期,请问应该怎么设置才正常
[Fact]
public void JsonTest()
{
var input = new A()
{
MyProperty = new Tuple<string, string>("1", "1"),
MyProperty2 = "1"
};
var jsonStr = JsonConvert.SerializeObject(input);
Log.Information(jsonStr);
input = JsonConvert.DeserializeObject<A>(jsonStr);
jsonStr = JsonConvert.SerializeObject(input);
Log.Information(jsonStr);
}
class A
{
public A()
{
MyProperty = new Tuple<string, string>("2", "2");//把这一行去掉就正常
MyProperty2 = "3";
}
public Tuple<string, string> MyProperty { get; set; }
public string MyProperty2 { get; set; } = "2";
}
输出结果为
[14:58:09 INF] {"MyProperty":{"Item1":"1","Item2":"1"},"MyProperty2":"1"}
[14:58:09 INF] {"MyProperty":{"Item1":"2","Item2":"2"},"MyProperty2":"1"}//期望的结果是和上面一样,但是MyProperty却变了
相关问题
- Jackson Deserialization not calling deserialize on
- Sorting 3 numbers without branching [closed]
- How to maintain order of key-value in DataFrame sa
- Graphics.DrawImage() - Throws out of memory except
- StackExchange API - Deserialize Date in JSON Respo
因为里面的属性是只读的不能被修改