【发布时间】:2021-10-08 07:06:04
【问题描述】:
我有一个像这样的 json 文件:
[
{
"Id": "Id1",
"Value": "Value1"
},
{
"Id": "Id2",
"Value": "Value2"
},
{
"Id": "Id3",
"Value": "Value3"
}
]
我需要将它移动到一个简单的 Dictionary(string, string) 并且 id 应该是键和值 - 值。
我可以修剪它并使用JsonDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);,但我认为应该有更简单的方法。
【问题讨论】:
-
将其反序列化为具有Id和Value属性的对象列表,然后使用
.ToDictionary转换为字典。
标签: c# json dictionary