Python Flask无法从发送文件响应对象获取JSON
使用Flask,我尝试使用Python Flask无法从发送文件响应对象获取JSON,python,flask,Python,Flask,使用Flask,我尝试使用send\u from\u directory加载静态JSON文件。从中我得到一个响应对象。我无法以JSON格式获取此对象;不过 courses = send_from_directory("static/", "courses.json"); courses["math"] # not a JSON - cannot get math element from loaded courses jsonify(courses) # Object of type Respo
send\u from\u directory
加载静态JSON文件。从中我得到一个响应
对象。我无法以JSON格式获取此对象;不过
courses = send_from_directory("static/", "courses.json");
courses["math"] # not a JSON - cannot get math element from loaded courses
jsonify(courses) # Object of type Response is not JSON serializable
那么,如何将响应转换为JSON格式呢
编辑:澄清一下-我不想返回文件和JSON。我试图从位于工作目录“/static”中的JSON文件中获取一个dict
。尝试以下操作:
import json
courses = send_from_directory("static/", "courses.json");
courses_dict = json.loads(courses)
print(courses_dict["math"])