开发者

Serializing resultset returned from mysqldb in python

开发者 https://www.devze.com 2022-12-13 19:11 出处:网络
Can anyone please help me in serializing resultset returned 开发者_运维百科using mysqldb in python?

Can anyone please help me in serializing resultset returned 开发者_运维百科using mysqldb in python?

I get typeerror: datetime.date(2007, 11, 15) is not JSON serializable

What is the best way to do serialize into Json object in python?

I am using json.dumps(resultset) to serialize resultset...


Set the "default" function passed to json.dump:

>>> d=datetime.datetime.now()
>>> json.dumps(d,default=str)
'"2009-12-18 14:22:21.405095"'


You can use rfc3339 strings instead:

  json.dump(datetime.now().strftime('%Y-%m-%dT%H:%M:%S'))

See: JSON datetime between Python and JavaScript


Serializing Django objects (Django Docs)

Serializing Python Objects (Dive Into Python 3)

0

精彩评论

暂无评论...
验证码 换一张
取 消