Код: Выделить всё
{
"desc": "my desc",
"lang": "en",
"issue": {
"date": "2024-09-01",
"title": "Empowering Razor Club"
},
"stars": [
{
"id": 1,
"value": 5
},
{
"id": 2,
"value": 4
}
]
}
Использовать Newtonsoft.Json SelectToken легко, поставив точку (.) для вложенных свойств или даже массивов. например "issue.title" или "stars[0].value". Когда дело доходит до System.Text.Json, мне сложнее.
Код: Выделить всё
private void UpdateJsonValue(string path, object value)
{
var json = "the above sample"
var node = JsonNode.Parse(json);
node[path] = JsonValue.Create(value); //error's here
json = node.ToJsonString();
//save json to file
}
UpdateJsonValue("issue.title", "Hello World");
UpdateJsonValue("stars[[1].value", 5);
Подробнее здесь: https://stackoverflow.com/questions/790 ... ck-to-file