python webpy 输出json响应,webpyjson,webpy输出json首


webpy输出json首先需要引用json包

import json

在Controller类中需要先设置输出Content-Type的响应头为text/json,然后输出json.dumps({})对象即可,如下demo代码:

class JsonTest:    def GET(self):        web.header('content-type','text/json')        return json.dumps({'key1':'value1','key2':'value2'})

就是这么简单。

评论关闭