json
package main

import (
	"encoding/json"
	"fmt"
)

type AutoGenerated struct {
	Age   int    `json:"age"`
	Name  string `json:"name"`
	Child []int  `json:"child"`
}

func main() {
	jsonStr1 := `{"age": 14,"name": "potter", "child":[1,2,3]}`
	a := AutoGenerated{}
	json.Unmarshal([]byte(jsonStr1), &a)
	aa := a.Child
	fmt.Println(aa)
	jsonStr2 := `{"age": 12,"name": "potter", "child":[3,4,5,7,8,9]}`
	json.Unmarshal([]byte(jsonStr2), &a)
	fmt.Println(aa)
}
  • A. [1 2 3] [1 2 3]
  • B. [1 2 3] [3 4 5]
  • C. [1 2 3] [3 4 5 6 7 8 9]
  • D. [1 2 3] [3 4 5 0 0 0]
Answer
Try it
B
json1
package main

import (
	"encoding/json"
	"fmt"
	"time"
)

func main() {
	t := struct {
		time.Time
		N int
	}{
		time.Date(2020, 12, 20, 0, 0, 0, 0, time.UTC),
		5,
	}

	m, _ := json.Marshal(t)
	fmt.Printf("%s", m)
}
  • A. {“Time”:“2020-12-20T00:00:00Z”,“N”:5}
  • B. “2020-12-20T00:00:00Z”
  • C. {“N”:5}
  • D. <nil>
  • E. 其他
Answer
Try it
B