How to overcome “datetime.datetime not JSON serializable”?

后端 未结 30 3519
梦谈多话
梦谈多话 2020-11-22 03:31

I have a basic dict as follows:

sample = {}
sample[\'title\'] = \"String\"
sample[\'somedate\'] = somedatetimehere
         


        
30条回答
  •  情书的邮戳
    2020-11-22 04:05

    The simplest way to do this is to change the part of the dict that is in datetime format to isoformat. That value will effectively be a string in isoformat which json is ok with.

    v_dict = version.dict()
    v_dict['created_at'] = v_dict['created_at'].isoformat()
    

提交回复
热议问题