【发布时间】:2020-06-30 10:32:41
【问题描述】:
如何将 JSON 文件的所有内容加载到我的项目中?我使用 Python-Django 作为我的后端,使用 MongoDB 作为我的数据库。我正在尝试将 JSON 文件的内容存储到 MongoDB (Djongo)
【问题讨论】:
如何将 JSON 文件的所有内容加载到我的项目中?我使用 Python-Django 作为我的后端,使用 MongoDB 作为我的数据库。我正在尝试将 JSON 文件的内容存储到 MongoDB (Djongo)
【问题讨论】:
试试:
import os
import json
from django.core.files.storage import default_storage
path = 'path/to/file.json'
default_storage.open(path).read()
# You may have to decode from Bytes to utf-8
# If you need to parse it to an array:
json = json.loads(data)
【讨论】: