Как мне получить Dict, вложенный внутри массива Dict в Python?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как мне получить Dict, вложенный внутри массива Dict в Python?

Сообщение Anonymous »

У меня есть список тем, и я могу без проблем перемещаться по основному разделу тем. Однако когда я пытаюсь выполнить действия, я постоянно получаю сообщение об ошибке. Вот синтаксис для одной темы:

Код: Выделить всё

[
{
"Topic Id": null,
"Topic Name": null,
"Topic Title": null,
"Topic Summary": null,
"Topic Matching Information": null,
"Actions": {
"actions": [
{
"action_id": "1",
"action_title": "Review Video",
"action_summary": "Watch the video",
"assigned_to": "nomail@email.com",
"due_date": "2024-05-24",
"action_attachments": [],
"action_owner": "Rumble",
"action_status": "Open"
},
{
"action_id": "2",
"action_title": "Review Barker Dam Annual Spill",
"action_summary": "Read the email about Barker Dam\u2019s Annual Spill Expected in Coming Days.",
"assigned_to": "noemail@email.com",
"due_date": "2024-05-24",
"action_attachments": [],
"action_owner": "Your Lower Chautauqua neighbors",
"action_status": "Open"
}
]
}
},
{
"Topic Id": "new_topic_001",
"Topic Name": "G-File Notification",
"Topic Title": "G-File Update Notification",
"Topic Summary": "Notification about the absence of today's G-File and an update on upcoming content.",
"Topic Matching Information": {
"subject": "About Today\u2019s G-File",
"sender": "",
"recipient": "",
"keywords": [
"G-File",
"newsletter"
]
},
"Actions": {
"actions": [
{
"action_id": "1",
"action_title": "Review Today's G-File",
"action_summary": "John Smith needs to review the G-File sent on 2024-05-17.",
"assigned_to": "John Smith",
"due_date": "2024-05-18",
"action_attachments": [],
"action_owner": "John Smith",
"action_status": "None"
}
]
}
}
]
Я перепробовал все, что мог придумать, а именно:

Код: Выделить всё

for this_topic in topics:
for this_action in this_topic["Actions"]["actions"]:
Я попробовал ["Action"].get("actions") и ["Action"][0]
Я постоянно получаю сообщение об ошибке:

Код: Выделить всё

TypeError: list indices must be integers or slices, not str
Может кто-нибудь помочь мне понять, что я делаю неправильно?


Подробнее здесь: https://stackoverflow.com/questions/785 ... -in-python
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»