Get a value by index from an array in interface

Viewed 20

I'm getting an interface which was created from json by json.Unmarshal.

It contains arrays. How do i get a value from a specific index in array? I know how to get a value from the first level map , but not from the arrays inside.

For example:

order := []byte(`{"price":10,"items":["banana","apple"]}`)
var orderObject map[string]interface{}
json.Unmarshal([]byte(order), &orderObject)

fmt.Println(orderObject["items"])

This gives the content of items array. How do i get the first , or second item?

I was hoping to something like orderObject["items"][0] , but that's doesn't work

0 Answers
Related