Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打印python嵌套字典中的int值&x27;int';对象是不可编辑的_Python_Json_Dictionary - Fatal编程技术网

打印python嵌套字典中的int值&x27;int';对象是不可编辑的

打印python嵌套字典中的int值&x27;int';对象是不可编辑的,python,json,dictionary,Python,Json,Dictionary,我试图访问一个嵌套的JSON文件,并通过将其导入python字典来打印其数据。当我把它们打印出来时,最后一个值有一个错误,它是字典中的int值 这是我的JSON数据 { "time": { "Thursday": { "21:00": 4, "1:00": 1, "4:00": 1, "2:00": 1, "20:00": 2, "22:00": 1, "19:00": 1,

我试图访问一个嵌套的JSON文件,并通过将其导入python字典来打印其数据。当我把它们打印出来时,最后一个值有一个错误,它是字典中的int值

这是我的JSON数据

{
"time": {
    "Thursday": {
        "21:00": 4,
        "1:00": 1,
        "4:00": 1,
        "2:00": 1,
        "20:00": 2,
        "22:00": 1,
        "19:00": 1,
        "15:00": 2,
        "13:00": 1,
        "23:00": 2
    },
    "Wednesday": {
        "11:00": 2,
        "13:00": 2,
        "14:00": 1,
        "17:00": 1,
        "6:00": 1,
        "2:00": 1,
        "0:00": 2,
        "1:00": 1,
        "21:00": 1,
        "18:00": 1,
        "19:00": 1,
        "20:00": 2
    },
    "Sunday": {
        "18:00": 1,
        "16:00": 1,
        "14:00": 1,
        "19:00": 2,
        "17:00": 1,
        "23:00": 1,
        "21:00": 1,
        "20:00": 5,
        "6:00": 1,
        "0:00": 1,
        "2:00": 2,
        "3:00": 3
    },
    "Friday": {
        "16:00": 1,
        "14:00": 2,
        "10:00": 2,
        "23:00": 1,
        "19:00": 2,
        "18:00": 1,
        "15:00": 1,
        "21:00": 2,
        "22:00": 2,
        "3:00": 1,
        "0:00": 2
    },
    "Saturday": {
        "21:00": 1,
        "23:00": 3,
        "18:00": 4,
        "10:00": 1,
        "12:00": 1,
        "13:00": 3,
        "14:00": 1,
        "15:00": 1,
        "16:00": 2,
        "17:00": 3,
        "2:00": 1,
        "0:00": 1,
        "1:00": 2
    },
    "Monday": {
        "12:00": 1,
        "11:00": 1,
        "14:00": 1,
        "18:00": 1,
        "19:00": 1,
        "23:00": 1,
        "20:00": 1
    },
    "Tuesday": {
        "18:00": 2,
        "12:00": 1,
        "13:00": 2,
        "16:00": 1,
        "15:00": 1,
        "4:00": 1,
        "21:00": 1,
        "20:00": 2,
        "23:00": 2
    }
},
"business_id": "7KPBkxAOEtb3QeIL9PEErg"
}

以下是我的python代码:

import json
with open('dataset/sample-checkin.json') as json_data:
    d = json.load(json_data)

for day in d["time"]:
    for time in d["time"][day]:
        for checkin in d["time"][day][time]:
            print(day, time, checkin)

错误:对于签入d[“time”][day][time]:TypeError:“int”对象不可编辑

最后一个循环没有意义。。。那边没什么可绕的。(正如错误所说,该值是一个
int
)我想您可能想要这样的值:

for day in d["time"]:
    for time in d["time"][day]:
        checkin = d["time"][day][time]
        print(day, time, checkin)