-2
im python中的編碼新手。我通常使用html,但我認爲是時候潛入新的東西。經過幾個小時的搜索和閱讀,我仍然感到困惑。在python 3中選擇特定的JSON響應項目
我想從這個JSON響應中選擇特定的數據。例如團隊名稱或事件ID。我真的很感激任何幫助,因爲我瘋了。這是python代碼和JSON響應的外觀。
import http.client
import json
from pprint import pprint
torneo = "424"
connection = http.client.HTTPConnection('api.football-data.org')
headers = { 'X-Auth-Token': '64172e9f948849e59f8b48ec17a3480d', 'X-Response-Control': 'minified' }
connection.request('GET', '/v1/soccerseasons/%s/fixtures/?timeFrame=n1' % torneo, None, headers)
response = json.loads(connection.getresponse().read().decode())
pprint (response)
{'count': 4,
'fixtures': [{'awayTeamId': 794,
'awayTeamName': 'Poland',
'date': '2016-06-21T16:00:00Z',
'homeTeamId': 790,
'homeTeamName': 'Ukraine',
'id': 149863,
'matchday': 3,
'result': {'goalsAwayTeam': None, 'goalsHomeTeam': None},
'soccerseasonId': 424,
'status': 'TIMED'},
{'awayTeamId': 759,
'awayTeamName': 'Germany',
'date': '2016-06-21T16:00:00Z',
'homeTeamId': 829,
'homeTeamName': 'Northern Ireland',
'id': 149862,
'matchday': 3,
'result': {'goalsAwayTeam': None, 'goalsHomeTeam': None},
'soccerseasonId': 424,
'status': 'TIMED'},
{'awayTeamId': 803,
'awayTeamName': 'Turkey',
'date': '2016-06-21T19:00:00Z',
'homeTeamId': 798,
'homeTeamName': 'Czech Republic',
'id': 149869,
'matchday': 3,
'result': {'goalsAwayTeam': None, 'goalsHomeTeam': None},
'soccerseasonId': 424,
'status': 'TIMED'},
{'awayTeamId': 760,
'awayTeamName': 'Spain',
'date': '2016-06-21T19:00:00Z',
'homeTeamId': 799,
'homeTeamName': 'Croatia',
'id': 149868,
'matchday': 3,
'result': {'goalsAwayTeam': None, 'goalsHomeTeam': None},
'soccerseasonId': 424,
'status': 'TIMED'}]}
Press ENTER to exit