JSON 構造に任意のパスを設定しようとしていますが、単純な設定値を行う方法がわかりません...
私が望むのは、SelectToken のように動作する SetValue(path,value) のようなメソッドですが、存在しない場合はパスを作成して値を設定します。
public void SetPreference(string username, string path, string value)
{
var prefs = GetPreferences(username);
var jprefs = JObject.Parse(prefs ?? @"{}");
var token = jprefs.SelectToken(path);
if (token != null)
{
// how to set the value of the path?
}
else
// how to add the path and value, example {"global.defaults.sort": { "true" }}
}
global.defaults.sort
パスとは実際には{ global: { defaults: { sort: { true } } } }