【问题标题】:Python Flask - Can't return boolean true [duplicate]Python Flask - 无法返回布尔值 true [重复]
【发布时间】:2019-06-14 02:44:20
【问题描述】:

我在Python Flask 中有一个简单的JSON 数组,就像这样..

response = [{
    "success" : true,
    "sessionid" : "sdf3452",
    "border" : {
        "top"    : "452",
        "left"   : "454",
    }
}]

js = json.dumps(response)
resp = Response(js, status=200, mimetype='application/json')
return resp

当我尝试这个时,我收到一个错误,抱怨真实值不存在......

NameError: name 'true' is not defined

知道为什么我不能返回布尔值 true 吗?

【问题讨论】:

  • 你拥有的不是 JSON 数组。它是 Python 源代码。 Python中没有true

标签: python flask


【解决方案1】:

回答了我自己的问题,python 布尔值 truefalse 大写。

response = [{
    "success" : True,
    "sessionid" : "sdf3452",
    "border" : {
        "top"    : "452",
        "left"   : "454",
    }
}]

js = json.dumps(response)
resp = Response(js, status=200, mimetype='application/json')
return resp

现在可以正常使用了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-27
    • 2017-05-03
    • 2012-11-16
    • 2017-09-16
    • 1970-01-01
    • 2011-02-27
    • 2012-09-26
    • 1970-01-01
    相关资源
    最近更新 更多