我的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
答案 0 :(得分:0)