我有一个像这样的json文档:
[
{
"TimerDuration": "1",
"UpdateDate": "a",
"DataBinding": [
{
"Name": "a",
"Path": "b"
},
{
"Name": "a",
"Path": "b"
}
]
}
]
这背后的类是:
internal class Settings
{
public String TimerDuration;
public String UpdateDate;
public List<DataBindings> DataBinding = new List<DataBindings>();
}
和:
internal class DataBindings
{
public String Name;
public String Path;
}
我想将文档反序列化成字符串,我可以使用。我该怎么做?
JSON 中的对象列表为 [] 意味着作为示例(使用 Newtonsoft),还请更具体说明您的意思是 [将文档反序列化为字符串]???
void Main()
{
string json = "[{\"TimerDuration\":\"1\",\"UpdateDate\":\"a\",\"DataBinding\":[{\"Name\":\"a\",\"Path\":\"b\"},{\"Name\":\"a\",\"Path\":\"b\"}]}]";
JsonConvert.DeserializeObject<List<Settings>>(json).Dump();
}
internal class Settings
{
public String TimerDuration;
public String UpdateDate;
public List<DataBindings> DataBinding = new List<DataBindings>();
}
internal class DataBindings
{
public String Name;
public String Path;
}