在折腾Flask去实现一个后台期间,需要搞清楚,对于POST和PUT中,如何获取传递进来的json参数
flask get put parameter
好像可以用:
data = request.data dataDict = json.loads(data)
貌似可以直接用:
request.get_json()
即可?
去看官网:
data
“get_json(force=False, silent=False, cache=True)
Parse and return the data as JSON. If the mimetype does not indicate JSON (application/json, seeis_json()), this returns None unless force is true. If parsing fails, on_json_loading_failed() is called and its return value is used as the return value.
Parameters:
* force – Ignore the mimetype and always try to parse JSON.
* silent – Silence parsing errors and return None instead.
* cache – Store the parsed JSON to return for subsequent calls.”
所以还是用get_json比较好用,注意调用接口时传入application/json就好