我试过这个例子:
import cherrypy
class Root(object):
@cherrypy.expose
@cherrypy.tools.json_out()
def getrange(self, limit=4):
return list(range(int(limit)))
cherrypy.quickstart(Root())
当我运行时,我得到:
Traceback (most recent call last):
File "D:/Dev/BaronPOS/baronpos/Server/tester.py", line 1, in <module>
import cherrypy
File "C:\Python27\lib\site-packages\cherrypy\__init__.py", line 62, in <module>
from cherrypy._cpcompat import urljoin as _urljoin, urlencode as _urlencode
File "C:\Python27\lib\site-packages\cherrypy\_cpcompat.py", line 244, in <module>
json_decode = json.JSONDecoder().decode
AttributeError: 'module' object has no attribute 'JSONDecoder'
我完全不知道为什么。我已经检查了模块是否存在以及类和两者都是。请帮忙!
答案 0 :(得分:1)
好的,我明白了。
我之前使用过SimpleJSONRPCServer(http://www.freenet.org.nz/dojo/pyjson/),但决定采用更灵活的REST兼容架构。
显然我留下了一个名为json.py的工件,这导致了这个......