【问题标题】:Loading JSON contents using django framework使用 django 框架加载 JSON 内容
【发布时间】:2020-06-30 10:32:41
【问题描述】:

如何将 JSON 文件的所有内容加载到我的项目中?我使用 Python-Django 作为我的后端,使用 MongoDB 作为我的数据库。我正在尝试将 JSON 文件的内容存储到 MongoDB (Djongo)

【问题讨论】:

    标签: python json django djongo


    【解决方案1】:

    试试:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      • 2018-06-24
      • 2014-08-23
      相关资源
      最近更新 更多