提交任务:
curl -i -H "Content-Type: application/json" -X POST -d '{"appIds": [ {"appid": "1076877374"}, {"appid": "1108288808"} ], "language": "cn", "EmailAddress": "", "ClusterNum": 2, "WordNum": 2, "EmailMessage": true, "ShowOnWebPage": true}' http://182.254.247.157:5000/ana
#!flask/bin/python
#encodig=utf-8
# _*_ coding:utf-8 _*_
# Writer : byz
# dateTime : 2016-08-05
from flask import Flask, jsonify, request, abort
import json
app = Flask(__name__)
@app.route('/ana', methods=['GET', 'POST'])
def call_analysis():
print "Hello, World!"
# if not request.json:(NO)
# abort(400)
#
# # data = request.get_json['appIds'] (NO)
# #
可用方式一:
data = request.data ----获取的是字符串
#
可用方式二:
data = request.get_data() ----获取的是字符串
#
(方式一和方式二得到的是原始提交的数据)
j_data = json.loads(data) -----load将字符串解析成json
print "j_data", j_data['language']
return jsonify(task_j)
# return jsonify({'task': runAnalysis(data)}), 201
json模块编码: json.dumps()
json模块解码:解码python json格式,用json.loads()
以下是从网上总结的问题,日后还用flask遇到麻烦的话可以来参看。