json - Golang SJSON 动态 JSON
问题描述
我在我的 golang 项目中使用 sjson。我想在我的项目中设置一些键值对。我有一个非结构化的动态对象。所以我无法知道路径。如下所示:
{
"temp1": {
"temp2": {
"password": "123456",
"country": "turkey",
"temp3": {
"password": "789654"
}
}
}
}
我想将密码值编辑为“秘密”,但在我的程序中我不知道路径。有没有前缀-posfix等...我该如何处理这个问题?
解决方案
我在不使用 sjson 的情况下解决了它,而是使用如下递归函数:
func changePassword(myMap map[string]interface{}) {
for key, value := range myMap {
if key == "password" {
myMap [key] = "******"
}
if _, ok := value.(map[string]interface{}); ok {
changePassword(value.(map[string]interface{}))
}
}
}
推荐阅读
- javascript - 为什么该功能不会在点击时发出警报?
- shopware - 由于连接被拒绝而无法安装应用程序?
- python - 使用多个字段过滤模型
- reactjs - 如何使用循环声明多个变量 useRef?那可能吗
- python - 给定一个包含 N 个元素的数组。任务是检查数组中的元素是否首先严格增加然后严格减少
- django - 使用上下文变量与 Django 中的 forloop.revcounter 进行比较
- android - 当清单中有`android:supportsRtl =“false”`时,如何在运行时更改ConstraintLayout的布局方向?
- groovy - 从目录中合并N个文件并存储在groovy中的一个文件中
- acrobat - \pdfmark(Acrobat Distiller)的官方文档中的错误
- vue.js - 如果我真的不需要 3d 动画,我可以使用 translate(2d) 而不是默认的 translate3d 来刷卡吗?