0
我试图访问嵌套的JSON文件,并通过将它们导入python字典来打印它的数据。当我将它们打印出来时,最后一个值是来自字典的int值。从Python嵌套字典中打印int值,'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签到[ “时间”] [天] [时间]:TypeError:'int'对象不可迭代