package main import ( "encoding/json" "fmt" ) type detail struct { Ip string NetType string Start int End int } type Config struct { Host string Nodes map[string]detail } func main() { var config Config file := []byte(`{ "host": "127.0.0.1:9090", "nodes": { "node_1": { "ip":"192.168.1.195:5000", "netType":"server", "start":1, "end":60 } } }`) json.Unmarshal(file, &config) fmt.Printf("Results: %v\n", config) fmt.Println(config.Nodes) } Results: {127.0.0.1:9090 map[node_1:{192.168.1.195:5000 server 1 60}]} map[node_1:{192.168.1.195:5000 server 1 60}] 结果不对,求指点。
有疑问加站长微信联系(非本文作者)
