如何在python中解析字典
我正在使用API“chess.com”,并试图学习更好的dict:如何在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
{'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])