我有一些JSON存儲在文件中,如下所示。我想要做的是找到Task2
,將其狀態從complete
更改爲deleted
,然後將其保存回我從中獲得的文本文件。但對於我的生活,我無法弄清楚這一點。更新存儲在文件中的JSON
這裏是我的JSON:
{
"tasks": [
{
"task" : "Task1",
"quantity" : "(1)",
"state" : "incomplete",
"changed" : "never"
},
{
"task" : "Task2",
"quantity" : "(1)",
"state" : "complete",
"changed" : "never"
},
{
"task" : "Task3",
"quantity" : "(1)",
"state" : "deleted",
"changed" : "never"
}
]
}
這是我迄今(使用Json.Net)
using (StreamReader reader = new StreamReader(fileStream))
{
string txt = reader.ReadToEnd();
JObject jObject = JObject.Parse(txt);
JArray tasks = (JArray) jObject["tasks"];
....
reader.Close();
}
,我需要以更新的JSON什麼代碼的代碼?