可以說,我有以下的JSON如何從golang中解析json的非標準時間格式?
{
name: "John",
birth_date: "1996-10-07"
}
,我想它解碼成以下結構
type Person struct {
Name string `json:"name"`
BirthDate time.Time `json:"birth_date"`
}
這樣
person := Person{}
decoder := json.NewDecoder(req.Body);
if err := decoder.Decode(&person); err != nil {
log.Println(err)
}
它給我的錯誤parsing time ""1996-10-07"" as ""2006-01-02T15:04:05Z07:00"": cannot parse """ as "T"
如果我要解析它手動LY我會做這樣的
t, err := time.Parse("2006-01-02", "1996-10-07")
但是當時間值是一個JSON字符串請問如何解碼器解析它在上面的格式?
[解析陶醉一個JSON日期時間(可能的重複https://stackoverflow.com/questions/ 44705817/parsing-a-json-date-in-revel) – RickyA
[在golang中解析日期字符串]可能的副本(https://stackoverflow.com/questions/25845172/parsing-date-string-in-golang) – Adrian