I am writing a websocket client in Go. I get the following JSON from the server:
{"args":[{"time":"2013-05-21 16:57:17"}],"name":"send:time"}
I am trying to access the time parameter, but just can't figure out how to penetrate deep into the interface type:
package main; import "encoding/json" import "log" func main() { msg := `{"args":[{"time":"2013-05-21 16:56:16", "tzs":[{"name":"GMT"}]}],"name":"send:time"}` u := map[string]interface{}{} err := json.Unmarshal([]byte(msg), &u) if err != nil { panic(err) } args := u["args"] log.Println( args[0]["time"] ) // invalid notation... }
Which are obviously errors, since the notation is incorrect:
invalid operation: args[0] (index of type interface {})
I just can't find a way to dig a map to capture deeply nested keys and values.
As soon as I can intercept dynamic values, I would like to declare these messages. How to write a type structure to represent such complex data structures?
go
ojosilva May 21 '13 at 15:42 2013-05-21 15:42
source share