Answer the question
In order to leave comments, you need to log in
How to write the same fields from json with different values?
"contact_groups": [
{
"contacts": [
{
"type": "phone",
"value": "+73903124090",
},
{
"type": "phone",
"value": "+73903122241",
},
{
"type": "phone",
"value": "+73903124024",
}
]
}
],
for contacts in listing['contact_groups']:
for contact in contacts['contacts']:
if (contact['type'] == 'phone'):
com_phones = contact['value']
else:
com_phones = ''
Answer the question
In order to leave comments, you need to log in
for contacts in listing['contact_groups']:
com_phones = []
for contact in contacts['contacts']:
if (contact['type'] == 'phone'):
com_phones.append(contact['value'])
...
Now it looks like this:
com_phones = []
if ('contact_groups' in listing):
for contacts in listing['contact_groups']:
for contact in contacts['contacts']:
if (contact['type'] == 'phone'):
com_phones.append(contact['value'])
else:
com_phones = ''
print(com_phones) # Тут список телефонов
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question