如何使用 bottle 返回 JSON 数组 - 最小示例

bottle 中返回 JSON 数组涉及将响应内容类型设置为 application/json,然后使用 json.dumps() 手动转储数组:

bottle_return_json.py
#!/usr/bin/env python3
from bottle import route, run, response
import json

@route('/')
def json_array():
    response.content_type = 'application/json'
    return json.dumps(["a", "b", "c"])

run(host='localhost', port=9000)

Check out similar posts by category: Python