【发布时间】:2013-11-28 15:52:24
【问题描述】:
我在 .Net 4.5 中使用 Json.Net,当在以下对象上使用填充对象时,它会使用 json 的内容增加 List 的值,而不是设置它的值。
Json.Net
JsonConvert.PopulateObject(string, object)
类
class MySettingSubClass
{
public List<string> MyStringList1 = new List<string>(){"one", "two", "three"}
}
class MySetting
{
public string MyString = "MyString";
public int MyInt = 5;
public MySettingSubClass MyClassObject = new MySettingSubClass();
public List<string> MyStringList2 = new List<string>{"one", "two", "three"};
}
当它们最初加载时,一切都是正确的,但是从 JSON 重新加载两个 MyStringLists 都是重复的"one", "two", "three", "one", "two", "three"
【问题讨论】: