我正在尝试使用 golang 中的 JSON.Marshal() 从地图创建 JSON 字符串。但是,int 值显示为用双引号括起来的字符串。
我的代码输出:
{ "age":
{
"$gt":"22",
"$lt":"20"
},
"location":
{
"$eq":"london"
},
"name":{
"$eq":"fred"
}
}
Run Code Online (Sandbox Code Playgroud)
代替
{ "age":
{
"$gt":22,
"$lt":20
},
"location":
{
"$eq":"london"
},
"name":{
"$eq":"fred"
}
}
Run Code Online (Sandbox Code Playgroud)
我在用:
var output_map = map[string]map[string]string{}
//Populate map here
output_json, err := json.Marshal(output_map)
if err!= nil {
fmt.Println("Error encoding JSON")
}
fmt.Println(output_json)
Run Code Online (Sandbox Code Playgroud)
我的理解是,如果提供了整数,JSON.Marshal() 将正确打印整数,但我的地图不会包含整数。我可以将地图更改为map[string]map[string]int{},但它不会包含“name”和“location”的字符串值。
最终的问题是我需要映射包含 int 和 string 值。某种地图[字符串]地图[字符串]{}。
我怎样才能实现这个目标?先感谢您。
哈利
我的 Kubernetes 集群有问题,我的 kube-scheduler pod 卡在“CrashLoopBackOff”状态,我无法纠正它。日志抱怨缺少服务令牌:
kubectl logs kube-scheduler-master -n kube-system
I1011 09:01:04.309289 1 serving.go:319] Generated self-signed cert in-memory
W1011 09:01:20.579733 1 authentication.go:387] failed to read in-cluster kubeconfig for delegated authentication: open /var/run/secrets/kubernetes.io/serviceaccount/token: no such file or directory
W1011 09:01:20.579889 1 authentication.go:249] No authentication-kubeconfig provided in order to lookup client-ca-file in configmap/extension-apiserver-authentication in kube-system, so client certificate authentication won't work.
W1011 09:01:20.579917 1 authentication.go:252] No authentication-kubeconfig provided in order to lookup requestheader-client-ca-file in configmap/extension-apiserver-authentication in kube-system, so request-header client certificate …Run Code Online (Sandbox Code Playgroud)