json编码,用map转换的问题。

ZhaoMingfang · · 4951 次点击
ooo,好的,我再找找书看看,麻烦了,谢谢了。
#6
更多评论
如果在contact里面再加一个整数,还能用map[string]string来接收吗 "contact": { "home": "415.333.3333", "cell": "415.555.5555", "i": 10 } 为了保持一致,标准库在unmarshal json object到interface{}类型时统一目的类型为map[string]interface{} To unmarshal JSON into an interface value, Unmarshal stores one of these in the interface value: bool, for JSON booleans float64, for JSON numbers string, for JSON strings []interface{}, for JSON arrays map[string]interface{}, for JSON objects nil for JSON null https://golang.org/pkg/encoding/json/#Unmarshal
#1
polaris
社区,需要你我一同完善!
consact 只是你意想的,是 map[string]string,但实际上完全可以这样: ``` "contact": { "home": "415.333.3333", "cell": "415.555.5555", "abc", 12 } ``` 所以,json 解析后,对应的 map 一定是 map[string]interface{}
#2