繁体   English   中英

TypeError:必须以JSONDecoder实例作为第一个参数来调用未绑定的方法encode()(改为使用PrintJson实例)

[英]TypeError: unbound method decode() must be called with JSONDecoder instance as first argument (got PrintJson instance instead)

TypeError:必须以JSONDecoder实例作为第一个参数来调用未绑定的方法encode()(改为使用PrintJson实例)

当我尝试将python对象解析为json时出现此错误。

使用以下代码:

import json
from json import JSONDecoder

class TestJson():
    name = None
    pass

printJson = PrintJson()
print printJson
print JSONDecoder.decode(printJson) // at this line, getting this error

这是因为您是在JSONDecoder类上而不是在其实例上调用该方法。 这将工作:

from json import JSONDecoder()
JSONDecoder().decode('{}')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM