bottle kullanarak JSON dizisi döndürme - minimal örnek

bottle‘da JSON dizisi döndürmek, yanıt içerik türünü application/json olarak ayarlamayı ve ardından diziyi json.dumps() kullanarak manuel olarak dump etmeyi içerir:

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