JSON array to C# Dictionary

后端 未结 6 1345
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 14:04

How do I convert a JSON array like this

[{\"myKey\":\"myValue\"},
{\"anotherKey\":\"anotherValue\"}]

to a C# Dictionary wi

6条回答
  •  别那么骄傲
    2020-12-19 14:12

    Maybe converting to array of KeyValuePairs will help

    using System.Linq;
    
    var list = JsonConvert.DeserializeObject>>(jsonContent);
    var dictionary = list.ToDictionary(x => x.Key, x => x.Value);
    

提交回复
热议问题