【发布时间】:2018-07-17 01:23:58
【问题描述】:
您好,我有一本正在使用的字典。
Dictionary<string, string> myProperties
我正在尝试将其格式化为 JSON,但遇到了困难。我需要它是这样的:
{
"properties": [
{
"property": "firstname",
"value": "John"
},
{
"property": "lastname",
"value": "Doe"
},
{
"property": "country",
"value": "united states"
}
]
}
目前我正在使用 Json.NET 来序列化字典,但这给了我这个:
{
"country": "united states",
"firstname": "John",
"lastname": "Doe"
}
谁能帮我把它格式化成我需要的格式。任何帮助将不胜感激。
【问题讨论】:
-
如果您使用 Visual Studio 的 编辑 -> 选择性粘贴 -> 将 JSON 粘贴为类 将所需的 JSON 粘贴到代码中,它将创建该 JSON 所需的类(您需要
List<Of Them>)。这样的课程也会让你过去的问题变得更容易。
标签: c# json http dictionary json.net