pip install flask
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def index():
data = {
"large_number": 12345678901234567890
}
return jsonify(data)
if __name__ == '__main__':
app.run()
from flask import Flask, Response
import simplejson as json
app = Flask(__name__)
@app.route('/')
def index():
data = {
"large_number": 12345678901234567890
}
return Response(json.dumps(data), mimetype='application/json')
if __name__ == '__main__':
app.run()
from flask import Flask, Response
app = Flask(__name__)
@app.route('/')
def index():
data = '''
John
28
New York
'''
return Response(data, mimetype='text/xml')
if __name__ == '__main__':
app.run(debug=True)
在 Flask 配置中加入下面一行代码就OK了。
if __name__ == '__main__':
app.config['JSON_AS_ASCII'] = False
app.run(debug=True)
json.dumps(data, ensure_ascii=False)