Golang创建JSON数组

I try to create json array

type Data struct {
Veggies Vegetables
array   array } type array map[string] []int
func main(){
vegetables := Vegetables{}
vegetables["Carrots"] = 21
n:= array{}
n  ["array"]= [] int {1, 1 ,1}
d := Data{ vegetables,n}

json.MarshalIndent(d, "", " ")}

please explain why not see the array?

The code above doesn't compile, but also has a few problems with the types. I'd avoid names like Array which could be confused for language keywords, and forgo the custom types. Maybe something simpler like this?

https://play.golang.org/p/OBw4gI2Zkm

type Data struct {
    Veggies map[string]int
    Ints    []int
}
...
j, err := json.MarshalIndent(d, "", " ")

The docs for the json package are good, you need to read them.

https://golang.org/pkg/encoding/json/#Marshal

For Go, this book is also great as an introduction to the language:

http://www.gopl.io/

To use an Unmarshaller, the struct data members need to be exported. That is, they need to be capitalized, or the unmarshaller does not have access. Capitalize Array in your Data struct. Veggies is the only one unmarshaled because it's capitalized and therefore exported.