简体   繁体   English

带瓶子返回Json Array

[英]Return Json Array with bottle

I am trying to return a Json array with Bottle. 我试图用Bottle返回一个Json数组。 The code is: 代码是:

@app.get('/getmyname')
def getmyname():
    ret = """{
            "chart": {
            "type": "column",
            }}""" 
    return json.dumps(ret)

However i get some unwanted characters in the resul which looks like this: 但是我在resul中得到了一些不需要的字符,如下所示:

"{\n\t\t\t\t\"chart\": {\n\t\t\t\t\t\"type\": \"column\",\n\t\t\t\t}}"

How could i fix this? 我该如何解决?

ret is already a JSON string. ret 已经是一个JSON字符串。 There is no need to call json.dumps on it. 无需在其上调用json.dumps

Either return ret directly, or create it as a Python dict and then dump it to JSON: 直接返回ret ,或将其创建为Python dict,然后将其转储到JSON:

ret = {
        "chart": {
            "type": "column",
         }
      }
return json.dumps(ret)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM