我是Golang的新手,解決了解析JSON的問題。一切正常,除了錯誤處理。Golang UnmarshalTypeError missing Offset
if err := json.Unmarshal(file, &configData); err != nil {
if ute, ok := err.(*json.UnmarshalTypeError); ok {
fmt.Printf("UnmarshalTypeError %v - %v - %v", ute.Value, ute.Type, ute.Offset)
}
}
在這裏,我得到錯誤ute.Offset undefined (type *json.UnmarshalTypeError has no field or method Offset)
但在Docs of JSON package也code他們在UnmarshalTypeError
結構這個變量。
我在做什麼錯了?謝謝
您使用的是哪個版本的Go? – kostya
在Go 1.5中添加了'UnmarshalTypeError.Offset':https://github.com/golang/go/blob/master/api/go1.5.txt#L286 – kostya
這就是問題所在。我有1.2.1,但不知道爲什麼。安裝在Ubuntu14.04上,apt-get就在昨天.. – Arxeiss