Here is a question from an absolute beginner python developer. Here is the challenge I have :)
not being able to access the "status" in this json file:
[{
"id": 0,
"sellerId": "HHH",
"lat": 90.293846,
"lon": 15.837098,
"evses": [{
"id": 0,
"status": 1,
"connectors": [{
"type": "Hyyyyp",
"maxKw": 22
}
]
}, {
"id": 2001,
"status": 2,
"connectors": [{
"type": "Hyyyyp",
"maxKw": 22
}
]
}, {
"id": 2002,
"status": 1,
"connectors": [{
"type": "Hyyyyp",
"maxKw": 22
}
]
}, {
"id": 2003,
"status": 1,
"connectors": [{
"type": "Hyyyp",
"maxKw": 22
}
]
}
]
}, {
"id": 10001,
"sellerId": 7705,
"lat": 12.59962,
"lon": 40.8767,
"evses": [{
"id": 10001,
"status": 1,
"connectors": [{
"type": "Tyyyyp",
"maxKw": 22
}
]
}, {
"id": 10002,
"status": 2,
"connectors": [{
"type": "Tyyyyp",
"maxKw": 22
}
]
}, {
"id": 10003,
"status": 2,
"connectors": [{
"type": "Tyyyyp",
"maxKw": 22
}
]
}, {
"id": 10004,
"status": 2,
"connectors": [{
"type": "Tyyyyp",
"maxKw": 22
}
]
}
]
}, {
for the "id:10001" there are 3 cases which "status: 2". So.. how do I print 3 for id:10001?
I guess I need to have an array for storying the ids itself and another array for storying the number of "status:2" for each id.
Here is my code: firs I do print id:
with open('sample.json') as f:
data = json.load(f)
print(id['id'])
Then I think I need to access array evses: So here is what I do:
print(data['evses'][0]['id']['status'])
But I get error on this line.
data['evses'][0]is a dictionary,data['evses'][0]['id']is 10001, it has no'status'keystatusis not a key ofid. dataID =data['evses'][0]['id']dataStatus =data['evses'][0]['status']