[英]How to deserialize list of objects from json
Thats my class.
class MyClass1 : IInterface1
{
public MyClass1()
{
this.Interface2s = new List<IInterface2>();
}
public string strI1 { get; set; }
public int intI1 { get; set; }
public IList<IInterface2> Interface2s { get; set; }
public int intC1 { get; set; }
}
在应用程序中,我使用一些随机值对其进行了序列化。 结果:
{
"strI1": "strI1",
"intI1": 2,
"Interface2s": [
{
"intI2": 111
},
{
"intI2": 222
},
{
"intI2": 333
}
]
}
然后,我想反序列化该字符串,但是我正在丢失IList中的值
result of deserialization next:
{
"strI1": "strI1",
"intI1": 2,
"Interface2s": [
{
"intI2": 0
},
{
"intI2": 0
},
{
"intI2": 0
}
]
}
要反序列化接口,我使用的是该示例http://www.newtonsoft.com/json/help/html/DeserializeWithDependencyInjection.htm
我也需要反序列化列表中的值。 有什么建议么?
我的建议只是使用http://www.newtonsoft.com/json
JsonConvert.SerializeObject(target)
并反序列化
JsonConvert.DeSerializeObject<MyClass1>(target)
它应该就这么简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.