嗨,我正在使用 JSON 编码器,其中 pickle.dumps() 给了我奇怪的输出。输出如下:
"cdecimal Decimal p0 (S'2097369' p1 tp2 Rp3 .",
虽然,它应该是:2097369
代码片段是:
class PythonObjectEncoder(JSONEncoder):
def default(self, obj):
if isinstance(obj, (list, dict, unicode, int, float, str, bool, type(None))):
return JSONEncoder.default(self, obj)
return pickle.dumps(obj)
def as_python_object(dct):
if '_python_object' in dct:
return pickle.loads('')
return dct
谁能告诉我出了什么问题,我怎样才能找回想要的价值?