【发布时间】:2020-03-24 01:10:13
【问题描述】:
我有字典,其中包含 json 路径和值:
Logging.Console.IncludeScopes = true
Logging.LogLevel.Microsoft = "Warning"
Logging.LogLevel.System= "Warning"
Sort.TypeOrder = "asc"
我想从这本词典生成 json。
{
"Logging": {
"Console": {
"IncludeScopes": true
},
"LogLevel": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"Sort": {
"TypeOrder": [
"asc"
]
}
}
我怎样才能做到这一点?
【问题讨论】:
-
不完全是你想要的,但也许这会给你一个想法:stackoverflow.com/q/4861138/6996150
-
对象可以通过像
NewtonSoft.Json这样的任何工具开箱即用地生成,这里的问题TypeOrder是如何转换为数组的?是否可以更新现有的类结构以在属性或类上添加 JsonConverter 属性? -
@johey 这是关于从简单的键值字典生成 json,我在键中有路径。
-
@PavelAnikhouski 我看过,但这不是我想要的。