早上好。我的appsettings.json文件中有一个对象数组:
"CustomFields": [
{
"GUID": "be283d29-12f0-4e02-be9f-050d7901269a",
"Key": "Key1",
"Type": 1
},
{
"GuidValue": "d8a2a939-fa5d-4b81-bdae-a53dce7d90b3",
"Key": "Key2",
"Type": 1
},
{
"GuidValue": "83302d3e-2a5f-4ea4-a250-80b939ef8b65",
"Key": "Key3",
"Type": 1
}
]
我想创建一个appsettings.Production.json来替换不同的GUID值,但保留具有相同GUID的设置。所以我的appsettings.Production.json看起来像:
"CustomFields": [
{
"GUID": "d9fa38aa-e676-49df-b75e-d643cdbfb18c",
"Key": "Key1",
"Type": 1
}
]
,但所有3个设置仍对应用程序可用。目前,它正在替换整个配置部分,仅在appsettings.Production.json中覆盖的字段可用。
我看过自定义构建器,自定义配置提供程序,但我一直无法弄清楚如何做到这一点。
有人可以告诉我如何仅替换配置部分中的某些值吗?
谢谢!
答案 0 :(得分:0)
在准备项目的应用程序设置时遇到了类似的问题。解决方法如下:
准备3个应用设置json文件:
-private func addClickToDismiss() {
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissPresentedView(_:)))
tapRecognizer.cancelsTouchesInView = false
presentedViewController.view.superview?.isUserInteractionEnabled = true
presentedViewController.view.superview?.addGestureRecognizer(tapRecognizer)
}
@objc
private func dismissPresentedView(_ sender: Any?) {
presentedViewController.dismiss(animated: true)
}
-appsettings.json
-appsettings.Development.json
appsettings.Production.json
中的{li> CustomFields
:appsettings.json
"CustomFields": []
中的CustomFields
:appsettings.Development.json
"CustomFields": [
{
"GUID": "be283d29-12f0-4e02-be9f-050d7901269a",
"Key": "Key1",
"Type": 1
},
{
"GuidValue": "d8a2a939-fa5d-4b81-bdae-a53dce7d90b3",
"Key": "Key2",
"Type": 1
},
{
"GuidValue": "83302d3e-2a5f-4ea4-a250-80b939ef8b65",
"Key": "Key3",
"Type": 1
}
]
中的{li> CustomFields
:appsettings.Production.json