Python JSON encoder to support datetime?

后端 未结 9 1925
长发绾君心
长发绾君心 2020-12-03 10:24

is there any elegant way to make Python JSON encoder support datetime? some 3rd party module or easy hack?

I am using tornado\'s database wrapper to fetch some rows

9条回答
  •  醉话见心
    2020-12-03 10:47

    json.dumps(r, default=lambda o: o.isoformat() if hasattr(o, 'isoformat') else o)
    

提交回复
热议问题