Answer the question
In order to leave comments, you need to log in
How to unpack complex json responses via python?
Good afternoon. Please tell me how to go through the for loop through a complex json response consisting of several blocks.
Example json response:
data =
[{"LocationId":1,"BlastHole":[{"Coords":{"X":15599.1298828125,"Y":35847.578125,"Z":180.10580444335938},"DesignMass":835.0,"AdditionalCharge":0.0,"RealAdditionalMass":0.0,"DesignHeight":9.992707,"RealMass":1301.0,"DesignExplosiveId":8,"RealHeight":15.56948,"RealExplosiveId":8,"Depth":10.0,"SourceHoleDepth":17.10579,"Tamping":0.0,"StatusId":4,"UnitId":4062,"StaffId":1019,"SecondStaffId":-1,"ShiftId":1,"Diameter":0.311,"StartTimestamp":"2020-08-18T08:46:39","EndTimeStamp":"2020-08-18T08:47:16","HoleNotes":null,"HoseLength":0.0,"BlockID":14999,"ID":717689,"Name":"100","OldName":null} . . . {} . . . {} . . . {}]
for i in data:
if i['BlastHole']['Name'] == '100':
print(['BlastHole']['SecondStaffId'])
i['BlastHole'][0]['Name']
Answer the question
In order to leave comments, you need to log in
data = [
{
"LocationId": 1, "BlastHole":
[
{
"Coords":
{
"X": 15599.1298828125, "Y": 35847.578125, "Z": 180.10580444335938
},
"DesignMass": 835.0,
"AdditionalCharge": 0.0,
"RealAdditionalMass": 0.0,
"DesignHeight": 9.992707,
"RealMass": 1301.0,
"DesignExplosiveId": 8,
"RealHeight": 15.56948,
"RealExplosiveId": 8,
"Depth": 10.0,
"SourceHoleDepth": 17.10579,
"Tamping": 0.0,
"StatusId": 4,
"UnitId": 4062,
"StaffId": 1019,
"SecondStaffId": -1,
"ShiftId": 1,
"Diameter": 0.311,
"StartTimestamp": "2020-08-18T08:46:39",
"EndTimeStamp": "2020-08-18T08:47:16",
"HoleNotes": "null",
"HoseLength": 0.0,
"BlockID": 14999,
"ID": 717689,
"Name": "100",
"OldName": "null"
}
]
}
]
for i in data:
print('BlastHole', i['BlastHole'])
if i['BlastHole']['Name'] == '100':
print(['BlastHole']['SecondStaffId'])
i['BlastHole'][0]['Name']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question