如何将烧瓶响应对象转换成字典 [英] How to turn Flask Response Object into Dictionary

查看:92
本文介绍了如何将烧瓶响应对象转换成字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道flask.jsonify返回一个烧瓶响应对象.但是我不知道如何将这个对象转换成字典.我将如何去做?

I understand that flask.jsonify returns a flask Response object. However I can't figure out how to convert this object into a dictionary. How would I go about doing this?

@app.route('/', methods=['GET'])
def hello(): #Accept and jsonify GET request from Nexmo
    if request.method == 'GET':
        info = jsonify(request.args.lists())
        #Turn info into dictionary here
        process(info)
        return info
    else:
        return 'Hello World!'

推荐答案

requests.args已经是类似于字典的对象,即

requests.args is already a dictionary-like object, a MultiDict. You do not need to use jsonify on it first.

您应该直接通过request.args调用process.

如果您确实想要字典,可以调用 request.args.to_dict(flat=False) .

If you really want a dict, you can call request.args.to_dict(flat=False).

这篇关于如何将烧瓶响应对象转换成字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆