I am trying to get the "id"
and "phone"
values in the data out of this json:
"status": "success",
"data": {
"id": "MertD43fdfdDdsjk",
"countrycode": "GB",
"country": "United Kingdom",
"createdAt": 15534534000,
"validUntil": 15534534000,
"service": "gmail",
"phone": "446576879809",
"price": 0.21
}
}
My current code is
json_data = json.loads(response.text)
#print(json_data)
values = json_data.items()
#print(values)
recieved = False
for key, value in values:
print(key, value)
if key == "id":
numid = value
print(numid)
elif key == "phone":
phone = value
print("Recieved the Phone Number - ",phone)
recieved = True
elif value == "Mobile number isn't received. Please try again":
if recieved == False:
getPhoneNumber()
I know I am only accessing status
and data
items and not the stuff inside of data
.
Currently, I am receiving the JSON as a result of requesting from an API so the values are always different.