21 lines
434 B
Python
21 lines
434 B
Python
|
"""
|
|||
|
@Time : 2022/10/17 10:12
|
|||
|
@Auth : 东
|
|||
|
@File :JSONEncodeTools.py
|
|||
|
@IDE :PyCharm
|
|||
|
@Motto:ABC(Always Be Coding)
|
|||
|
@Desc:
|
|||
|
|
|||
|
"""
|
|||
|
import datetime
|
|||
|
import json
|
|||
|
|
|||
|
|
|||
|
class MyEncoder(json.JSONEncoder):
|
|||
|
def default(self, obj):
|
|||
|
if isinstance(obj, bytes):
|
|||
|
return str(obj, encoding='utf-8')
|
|||
|
if isinstance(obj, datetime.datetime):
|
|||
|
return str(obj)
|
|||
|
|
|||
|
return json.JSONEncoder.default(self, obj)
|