在python中,我正在访问一个API,该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条警报的列表。如果我想为键“存档”打印任何警报的所有详细信息,且其值为“ false”,那么最好的方法是什么?我只需要查看有关当前警报的详细信息,而无需查看已存档的警报。如果我也传递了特定的AlertID,则该API还可以返回详细信息,该特定的网址为我提供了所有警报的列表。
答案 0 :(得分:0)
for alert in result['items']:
if alert.get('Archived') is False:
print(alert)
答案 1 :(得分:0)
这应该是一个简单的过滤器:
boolean anagrams = Stream.of(words)
.map(s -> IntBuffer.wrap(s.chars().sorted().toArray()))
.distinct().count() == 1;
这将为您提供已归档为假的所有项目正文的列表。您可以编写另一个函数来处理它们:
alerts = api_response['items']
live_alerts = [alert for alert in alerts if not alert['Archived']]
答案 2 :(得分:0)
您应该简单地假设您将其作为json对象,
if json_var["items"]["archived"] == false:
print <whatever info you want>
答案 3 :(得分:0)
尝试一下?我不认为由于items
而导致的其他作品是包含一个词典的列表。
print('\n'.join([e for e in result if not e['items'][0]['Archived']])