TypeError: unbound method decode() must be called with JSONDecoder instance as first argument (got PrintJson instance instead)
当我尝试将 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('{}')
关于python - 类型错误 : unbound method decode() must be called with JSONDecoder instance as first argument (got PrintJson instance instead),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32410334/