我想反序列化JSON並以最小的複雜性來反轉鍵/值。我有一個輸入的json,看起來像:C#反序列化JSON到字典和反向KV
{
"1":"apple",
"2":"banana",
"3":"orange",
"4":"grape"
}
而想要序列化此爲Dictionary<string,string>
,但扭轉字典這樣的水果是key
和整數是value
。任何方式來達到與Newtonsoft.Json
?
var obj = JsonConvert.DeserializeObject<Dictionary<string,string>>(json);
// obj.Keys = { "1", "2", "3" }, but I want them to be { "apple", "banana", ... }
*「複雜性最小」*代碼複雜度?時間複雜性?內存複雜? –