【发布时间】:2017-12-05 05:11:03
【问题描述】:
我尝试从具有未定义数量的未知键值的 JSON 创建字符串映射。
这是我的 JSON 文件示例:
{
"localhost":
{
"tag": "dev_latest",
"vhost": "localhost.com"
},
"development":
{
"tag": "dev_latest",
"vhost": "dev.com"
}
}
我想创建一个map[string]string,其值如下:
config := map[string]string{
"localhost-tag": "dev_latest",
"localhost-vhost": "localhost.com,
"development-tag": "dev_latest,
...
}
用已知值解析带有"github.com/jmoiron/jsonq" 的JSON 非常简单,但在这种情况下,localhost 可以是任何东西,tag 可以是任何其他东西。
我的 Go 代码中的入口点是这样的:
func ParseJson(){
configPath := GetConfigPath()
b, err := ioutil.ReadFile(configPath)
// Here, I need to create my map of strings..
return configKeyStr
}
任何帮助将不胜感激。
谢谢!
【问题讨论】:
标签: json string dictionary go unmarshalling