Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中解析字典_Python_Python 3.x_Dictionary - Fatal编程技术网

如何在python中解析字典

如何在python中解析字典,python,python-3.x,dictionary,Python,Python 3.x,Dictionary,我正在使用API“chess.com”,并试图学习更好的dict: {'url': 'https://www.chess.com/live/game/8554438187', 'pgn': '[Event "Live Chess"]\n[Site "Chess.com"]\n[Date "2021.03.03"]\n[Round "-"]\n[White "AHMEDAHMED1984"]\n[B

我正在使用API“chess.com”,并试图学习更好的dict:

{'url': 'https://www.chess.com/live/game/8554438187', 'pgn': '[Event "Live Chess"]\n[Site "Chess.com"]\n[Date "2021.03.03"]\n[Round "-"]\n[White "AHMEDAHMED1984"]\n[Black "pgmendormi"]\n[Result "0-1"]
我需要url,所以我做了:

data = get_player_game_archives(username).json

url = data['archives'][-1]
games = requests.get(url).json()

game = games['games'][-1]
print(games['games'][-1]['url'])
但是我怎样才能得到
“[结果“0-1”]”
我试过:

但它只给我一个字符,我必须做循环吗

怎么做


感谢您的回答:)

游戏['games'][-1][-pgn'].splitlines()[-1]
应该可以做到这一点。
数据=…
中的
.json()
似乎表明您正在获取json数据。在这种情况下,
json.loads(…)
可能会有用吗?谢谢你的提示:)
print(games['games'][-1]['url'][1])