美文网首页
python json模块与flask jsonify拓展包使用

python json模块与flask jsonify拓展包使用

作者: 灰太狼256 | 来源:发表于2019-05-04 21:04 被阅读0次

1.JSON数据格式

# json数据格式
{
"name": "tab",
"age": "25",
"height": "178",
"weight": "135"
}
# 另一种json数据格式
{
"name": "tab","age": "25","height": "178","weight": "135"}

2.python处理JSON

JSON数据格式转换成python的简单数据类型

# 简单数据类型:int/float/string/tuple/list/dict/unicode
import json
json.loads(json_data)

python的简单数据类型转换成JSON数据格式:

import json
json.dumps(data)

3.flask jsonify拓展包使用

from flask import Flask, jsonify

app = Flask(__name__)

data = {
  "name": "tab",
  "age": "25",
  "height": "178",
  "weight": "135"
}

@app.route('/')
def get_json():
  return jsonify(data)
  # return json.dumps(data)
app.run(debug=True)

相关文章

网友评论

      本文标题:python json模块与flask jsonify拓展包使用

      本文链接:https://www.haomeiwen.com/subject/bixgnqtx.html