json dumps

__author__ = 'zhaobin022'
import json
from datetime import datetime

class JsonCustomEncoder(json.JSONEncoder):
    def default(self,field):
        if isinstance(field,datetime):
            return field.strftime('%Y-%m-%d %H:%M:%S')




obj = {'d':datetime.now()}
ds = json.dumps(obj,cls=JsonCustomEncoder)
print(ds)

 

__author__ = 'zhaobin022'
import json
from datetime import datetime

class JsonCustomEncoder(json.JSONEncoder):
def default(self,field):
if isinstance(field,datetime):
return field.strftime('%Y-%m-%d %H:%M:%S')




obj = {'d':datetime.now()}
ds = json.dumps(obj,cls=JsonCustomEncoder)
print(ds)
posted on 2016-11-29 11:43  zhaobin022  阅读(177)  评论(0编辑  收藏  举报