<bdo id='99iz6'></bdo><ul id='99iz6'></ul>

    <tfoot id='99iz6'></tfoot><legend id='99iz6'><style id='99iz6'><dir id='99iz6'><q id='99iz6'></q></dir></style></legend>

      <small id='99iz6'></small><noframes id='99iz6'>

      <i id='99iz6'><tr id='99iz6'><dt id='99iz6'><q id='99iz6'><span id='99iz6'><b id='99iz6'><form id='99iz6'><ins id='99iz6'></ins><ul id='99iz6'></ul><sub id='99iz6'></sub></form><legend id='99iz6'></legend><bdo id='99iz6'><pre id='99iz6'><center id='99iz6'></center></pre></bdo></b><th id='99iz6'></th></span></q></dt></tr></i><div id='99iz6'><tfoot id='99iz6'></tfoot><dl id='99iz6'><fieldset id='99iz6'></fieldset></dl></div>
    1. json.dumps 与 flask.jsonify

      json.dumps vs flask.jsonify(json.dumps 与 flask.jsonify)
    2. <small id='GXhwp'></small><noframes id='GXhwp'>

        <i id='GXhwp'><tr id='GXhwp'><dt id='GXhwp'><q id='GXhwp'><span id='GXhwp'><b id='GXhwp'><form id='GXhwp'><ins id='GXhwp'></ins><ul id='GXhwp'></ul><sub id='GXhwp'></sub></form><legend id='GXhwp'></legend><bdo id='GXhwp'><pre id='GXhwp'><center id='GXhwp'></center></pre></bdo></b><th id='GXhwp'></th></span></q></dt></tr></i><div id='GXhwp'><tfoot id='GXhwp'></tfoot><dl id='GXhwp'><fieldset id='GXhwp'></fieldset></dl></div>
        <legend id='GXhwp'><style id='GXhwp'><dir id='GXhwp'><q id='GXhwp'></q></dir></style></legend>
            <tbody id='GXhwp'></tbody>

            • <tfoot id='GXhwp'></tfoot>
              • <bdo id='GXhwp'></bdo><ul id='GXhwp'></ul>
                本文介绍了json.dumps 与 flask.jsonify的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我不确定我是否理解 flask.jsonify 方法的目的.我尝试从中创建一个 JSON 字符串:

                I am not sure I understand the purpose of the flask.jsonify method. I try to make a JSON string from this:

                data = {"id": str(album.id), "title": album.title}
                

                但是我使用 json.dumps 得到的结果与使用 flask.jsonify 得到的不同.

                but what I get with json.dumps differs from what I get with flask.jsonify.

                json.dumps(data): [{"id": "4ea856fd6506ae0db42702dd", "title": "Business"}]
                flask.jsonify(data): {"id":…, "title":…}
                

                显然我需要得到一个看起来更像 json.dumps 返回的结果.我做错了什么?

                Obviously I need to get a result that looks more like what json.dumps returns. What am I doing wrong?

                推荐答案

                flask 中的 jsonify() 函数返回一个 flask.Response() 对象,该对象已经有了与 json 响应一起使用的适当的内容类型标头application/json".而 json.dumps() 方法只会返回一个编码字符串,这需要手动添加 MIME 类型标头.

                The jsonify() function in flask returns a flask.Response() object that already has the appropriate content-type header 'application/json' for use with json responses. Whereas, the json.dumps() method will just return an encoded string, which would require manually adding the MIME type header.

                查看更多关于 jsonify() 函数的信息这里 供完整参考.

                See more about the jsonify() function here for full reference.

                另外,我注意到 jsonify() 处理 kwargs 或字典,而 json.dumps() 还支持列表和其他.

                Also, I've noticed that jsonify() handles kwargs or dictionaries, while json.dumps() additionally supports lists and others.

                这篇关于json.dumps 与 flask.jsonify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                How to break out of multiple loops?(如何打破多个循环?)
                How to put the legend out of the plot(如何将传说从情节中剔除)
                Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                <i id='hCcfh'><tr id='hCcfh'><dt id='hCcfh'><q id='hCcfh'><span id='hCcfh'><b id='hCcfh'><form id='hCcfh'><ins id='hCcfh'></ins><ul id='hCcfh'></ul><sub id='hCcfh'></sub></form><legend id='hCcfh'></legend><bdo id='hCcfh'><pre id='hCcfh'><center id='hCcfh'></center></pre></bdo></b><th id='hCcfh'></th></span></q></dt></tr></i><div id='hCcfh'><tfoot id='hCcfh'></tfoot><dl id='hCcfh'><fieldset id='hCcfh'></fieldset></dl></div>

                <small id='hCcfh'></small><noframes id='hCcfh'>

                        <bdo id='hCcfh'></bdo><ul id='hCcfh'></ul>

                      • <tfoot id='hCcfh'></tfoot>
                        <legend id='hCcfh'><style id='hCcfh'><dir id='hCcfh'><q id='hCcfh'></q></dir></style></legend>
                          <tbody id='hCcfh'></tbody>