首页 > 解决方案 > 使用 django python 读取 json 文件

问题描述

我有一个 json 文件。我想在 django python 中读取 json 文件。

Json 文件包含

{
    "ATM Cash" : ["withdrawal"],
    "Expense" :["fees","goods","stationery","purchase","material","telephone"],
    "Income" : ["salary","deposit","rewards"],
    "Payment" : ["tranfer","payment"],
    "Medical" : ["dr ", 
       "doctor","dr.","nursing","pharmacist","physician","hospital","medicine"],
    "Food/Restaurent" :["food","catering"],
    "Groceries" : ["big bazar"],
    "Shopping" : ["cloths"],
    "Mobile recharge" : ["airtel"],
    "Auto & Fuel" : ["fuel"],
    "Travel" : ["travel"],
    "General" : ["others"]
}

标签: jsondjangopython-3.x

解决方案


如果它是一个文件,那么使用json.load()like

import json
with open('path/to/file/file_name.json', 'r') as f:
    my_json_obj = json.load(f)

推荐阅读