使用 Go 解析 JSON 時,如果值為 null 或缺少值,是否可能失敗,而不必通過 if 語句檢查每個字段?例如:package mainimport ( "encoding/json" "fmt")type Bird struct { Species string `json:"birdType"` Description string `json:"what it does"`}func main() { birdJson := `{"birdType": "pigeon"}` var bird Bird json.Unmarshal([]byte(birdJson), &bird) fmt.Println(bird)}我希望引發錯誤,因為 未定義"what it does"
- 1 回答
- 0 關注
- 112 瀏覽
添加回答
舉報
0/150
提交
取消