初级会员
  • 第 34077 位会员
  • longhtml
  • 2019-04-09 09:11:57
  • Offline
  • 20 13

最近发布的文章

    暂无

最近分享的资源

    暂无

最近发布的项目

    暂无

最近的评论

  • #1 @18393910396 非常感谢支持! 最终这样解决问题了。 ``` package main import "fmt" import "encoding/json" func main() { json_list_str := `[{"ID":"7fab2946-9d9c-39d0-387e-a0239cf95351","Node":"consul-4","Address":"192.168.15.113","Datacenter":"dc1","TaggedAddresses":{"lan":"192.168.15.113","wan":"192.168.15.113"},"NodeMeta":{"consul-network-segment":""},"ServiceKind":"","ServiceID":"web4","ServiceName":"web4","ServiceTags":["master"],"ServiceAddress":"192.168.15.113","ServiceWeights":{"Passing":1,"Warning":1},"ServiceMeta":{},"ServicePort":8082,"ServiceEnableTagOverride":false,"ServiceProxyDestination":"","ServiceProxy":{},"ServiceConnect":{},"CreateIndex":2974,"ModifyIndex":2974}]` var result []map[string]interface{} err := json.Unmarshal([]byte(json_list_str), &result) fmt.Println(err, result) // 取出result变量里面的"Address"字段。 fmt.Println(err, result[0]["Address"]) // output // <nil> [map[ServiceKind: ServiceTags:[master] ServicePort:8082 ServiceProxyDestination: TaggedAddresses:map[lan:192.168.15.113 wan:192.168.15.113] ServiceAddress:192.168.15.113 ServiceEnableTagOverride:false ServiceProxy:map[] ServiceConnect:map[] ModifyIndex:2974 ID:7fab2946-9d9c-39d0-387e-a0239cf95351 Datacenter:dc1 ServiceID:web4 ServiceName:web4 ServiceMeta:map[] CreateIndex:2974 Node:consul-4 Address:192.168.15.113 NodeMeta:map[consul-network-segment:] ServiceWeights:map[Passing:1 Warning:1]]] // <nil> 192.168.15.113 } ```
  • #1 @18393910396 ``` var result map[string]interface{} err := json.Unmarshal([]byte(json_list_str), &result) fmt.Println(err, result) ``` 提示报错了。 json: cannot unmarshal array into Go value of type map[string]interface {} map[] 在线代码执行链接 https://www.bytelang.com/o/s/c/c9YRSqkXPFs=
  • json数据里面的"Address":"192.168.15.113",需要如何取出来?