错误日志:
Json Err: parsing time "null" as ""2006-01-02T15:04:05Z07:00"": cannot parse "null" as """
通过查找相关信息:
https://github.com/golang/go/commit/f444b48fe419c2d19b7b9a89faad30f0e8b0e474
Fixed : 9037
https://github.com/golang/go/issues/9037
go较高版本(1.8.0)已经修复该问题了, 而go 1.7.4 版本有该错误
测试代码:
package main
import (
"encoding/json"
"fmt"
"time"
)
type jsonStruct struct {
TestTime time.Time `json:"testtime"`
}
func unmarshal() {
jsonStr := `{"testtime":null}`
var jsons jsonStruct
err := json.Unmarshal([]byte(jsonStr), &jsons)
fmt.Println("Err: ", err)
fmt.Println("Json: ", jsons)
}
func main() {
unmarshal()
}