【发布时间】:2022-01-16 16:13:10
【问题描述】:
假设 JSON 响应 print(response) 的打印是:
{'incidents': [{'text': 'FT', 'homeScore': 2, 'awayScore': 0, 'isLive': False, 'time': 90, 'addedTime': 999, 'incidentType': 'period'}, {'player': {'name': 'Jackson Porozo', 'firstName': '', 'lastName': '', 'slug': 'jackson-porozo', 'shortName': 'J. Porozo', 'position': 'D', 'userCount': 321, 'id': 978518}, 'playerName': 'Jackson Porozo', 'reason': 'Foul', 'id': 120118989, 'time': 90, 'addedTime': 4, 'isHome': False, 'incidentClass': 'yellow', 'incidentType': 'card'}
我想知道我们是否在此回复中包含了'incidentType': 'card'。
为此我尝试使用:
if "'incidentType': 'card'" in response:
print('Ok')
我也尝试过使用:
if "\'incidentType\': \'card\'" in response:
print('Ok')
两者都没有返回Ok,我应该如何处理?
【问题讨论】: