I'm still in the learning process of Go but am hitting a wall when it comes to JSON response arrays. Whenever I try to access a nested element of the "objects" array, Go throws (type interface {} does not support indexing)
What is going wrong and how can I avoid making this mistake in the future?
package main
import (
"encoding/json"
"fmt"
)
func main() {
payload := []byte(`{"query": "QEACOR139GID","count": 1,"objects": [{"ITEM_ID": "QEACOR139GID","PROD_CLASS_ID": "BMXCPGRIPS","AVAILABLE": 19}]}`)
var result map[string]interface{}
if err := json.Unmarshal(payload, &result); err != nil {
panic(err)
}
fmt.Println(result["objects"]["ITEM_ID"])
}
http://play.golang.org/p/duW-meEABJ
edit: Fixed link