2024-04-29 02:31:39 发布
网友
我是这样做的吗?在
import cyclone class MyHandler(cyclone.web.RequestHandler): def get(self, command): details = {'status':'success'} json = json_encode(details) self.write(json)
或者还有更多吗?在
我建议使用内置的json encoder function:
self.write(tornado.escape.json_encode(details)
如果details是dict类型,tornado将自动对数据进行json编码。对于列表来说,情况并非如此。 从龙卷风密码(网页.py)公司名称:
Note that lists are not converted to JSON because of a potential cross-site security vulnerability. All JSON output should be wrapped in a dictionary. More details at http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx
它甚至比这还少:您可以简单地使用self.write(details)如果您编写dict,它将自动转换为JSON。在
self.write(details)
我建议使用内置的json encoder function:
如果details是dict类型,tornado将自动对数据进行json编码。对于列表来说,情况并非如此。 从龙卷风密码(网页.py)公司名称:
它甚至比这还少:您可以简单地使用
self.write(details)
如果您编写dict,它将自动转换为JSON。在相关问题 更多 >
编程相关推荐