[已解决]flask request get_json None

搜:
flask request get_json None
参考:
 return jsonify(request.get_json(force=True))
   content = request.get_json(silent=True)
If the mimetype is application/json this will contain the parsed JSON data. Otherwise this will be None.
get_json(force=False, silent=False, cache=True)
Parses the incoming JSON request data and returns it. If parsing fails the on_json_loading_failed() method on the request object will be invoked. By default this function will only load the json data if the mimetype is application/json but this can be overridden by the force parameter.
Parameters:
force – if set to True the mimetype is ignored.
silent – if set to True this method will fail silently and return None.
cache – if set to True the parsed JSON data is remembered on the request.
on_json_loading_failed(e)¶
Called if decoding of the JSON data failed. The return value of this method is used by get_json() when an error occurred. The default implementation just raises a BadRequest exception.
Changed in version 0.10: Removed buggy previous behavior of generating a random JSON response. If you want that behavior back you can trivially add it by subclassing.
New in version 0.8.
-》
加上:
force=True
变成:
request.get_json(force=True)
即可。


发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量