【发布时间】:2020-03-04 19:53:42
【问题描述】:
使用 Flask,我尝试使用 send_from_directory 加载静态 JSON 文件。从这里我得到一个Response 对象。我无法以 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。
【问题讨论】: