我的GoLang结构:
type myPojo struct {
ID bson.ObjectId `json:"id" bson:"_id,omitempty"`
Start time.Time `json:"start"`
}POST API JSON输入请求:
{
"Start":ISODate("2013-10-01T00:00:00.000Z")
}我的代码将输入JSON请求转换为Golang Struct:
func myPostApi(w http.ResponseWriter, r *http.Request, db mongoDB) {
w.Header().Set("Content-Type", "application/json")
decoder := json.NewDecoder(r.Body)
var inputObj myPojo
err := decoder.Decode(&inputObj)
if err != nil {
//This gets executed
log.Println("Error occurred converting POST input json to myPojo data.")
log.Println(err)
}
}上面的代码不能转换,如果块和打印下面的错误,它会进入内部错误,请帮助。
2018/02/25 22:12:44 Error occurred converting POST input json to myPojo data.
2018/02/25 22:12:44 invalid character 'I' looking for beginning of value发布于 2018-02-26 06:48:19
这个
ISODate("2013...")值不是有效的JSON。这看起来像一个符号或函数调用,这在JSON中是不允许的。并且JSON中没有date类型:
https://stackoverflow.com/questions/48978652
复制相似问题