go - Golang parse a json with DYNAMIC key -
i have json string follows:
j := `{"bvu62fu6dq": {            "name": "john",            "age": 23,            "xyz": "weu33s"            .....            .....}       }`   i want extract value of name , age above json string. looked @ example given @ golang site http://play.golang.org/p/yqgzp7kpp9
but problem key in json on top level dynamic. means bvu62fu6dq dynamic. have created struct this:
 type info struct {    uniqueid map[string]string  }   but not sure how extract name , age. code @ http://play.golang.org/p/vbdkd3xikc
i believe want this:
type person struct {     name string `json:"name"`     age  int    `json:"age"` }  type info map[string]person   then, after decoding works:
fmt.printf("%s: %d\n", info["bvu62fu6dq"].name, info["bvu62fu6dq"].age)   full example: http://play.golang.org/p/fyh-cdp3na
Comments
Post a Comment