【发布时间】:2018-10-29 15:06:29
【问题描述】:
在 python 中,我正在访问一个返回警报列表的 API,如下所示:
{
"items": [
{
"AlertID": 0,
"Code": 0,
"Source": "string",
"Title": "string",
"Severity": "Information",
"Created": "2018-10-29T14:57:05.639Z",
"ThresholdValue1": "string",
"ThresholdValue2": "string",
"ThresholdValue3": "string",
"ThresholdValue4": "string",
"ThresholdValue5": "string",
"SnoozedEndDate": "2018-10-29T14:57:05.639Z",
"DeviceGuid": "string",
"AdditionalInfo": "string",
"Archived": true,
"AlertCategoryID": "Hardware",
"ArchivedDate": "2018-10-29T14:57:05.639Z",
"TicketID": 0,
"AlertMessage": "string",
"DeviceName": "string",
"CustomerID": 0,
"CustomerName": "string",
"MessageTemplate": "string",
"FolderID": 0,
"PollingCyclesCount": 0
}
],
"totalItemCount": 0,
"page": 0,
"itemsInPage": 0,
"totalPages": 0,
"prevLink": "string",
"nextLink": "string"
}
这将返回一个包含 20 个警报的列表。如果我想打印键 'Archived' 的值为 'false' 的任何警报的所有详细信息,那么最好的方法是什么?我只需要查看有关当前警报的详细信息,而不是存档的警报。如果我也传入特定的 AlertID,API 也可以返回详细信息,这个特定的 url 为我提供了所有警报的列表。
【问题讨论】:
-
返回的是字符串还是字典?
-
API返回一个json字符串,然后我使用
json.loads将它序列化成一个dict。
标签: python json dictionary