Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Continuation of troubleshooting from my question on Stack overflow.
- # @MisterNox I really appreciate the time you have put into helping thus far. Here is my code.
- #import JSON
- import json
- #I define the txt2 path
- txt2 = '/Users/myname/Environments/my_env/Learning Python/Riot API/test_run2'
- #Open it so it can be read, as it needs to be read as JSON strings
- with open("/Users/myname/Environments/my_env/Learning Python/Riot API/test_run2", "r") as f:
- txt2 = f.read()
- #I implement your solution
- txt = json.loads(txt2.replace("'", '"'))
- output = [x["gameId"] for x in txt["matches"]]
- print(output)
- #___________________________________________________________
- #Contents of test_run2
- #This is EXACTLY what is in test_run2 as I am only using your JSON example. If I can get YOUR example to work I will mark the question as correct, because I know I can learn a bit more about JSON and easily get mine to work.
- """{'matches': [{'platformId': 'EUW1', 'gameId': 4728220480, 'champion': 121, 'queue': 420, 'season': 13, 'timestamp': 1595790394190, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4727511119, 'champion': 104, 'queue': 420, 'season': 13, 'timestamp': 1595776780604, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4727366101, 'champion': 121, 'queue': 420, 'season': 13, 'timestamp': 1595774913709, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4724700944, 'champion': 104, 'queue': 420, 'season': 13, 'timestamp': 1595632344294, 'role': 'DUO_SUPPORT', 'lane': 'NONE'}, {'platformId': 'EUW1', 'gameId': 4724662512, 'champion': 163, 'queue': 420, 'season': 13, 'timestamp': 1595629227345, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4724497303, 'champion': 203, 'queue': 420, 'season': 13, 'timestamp': 1595627065458, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4722652071, 'champion': 104, 'queue': 420, 'season': 13, 'timestamp': 1595530253160, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4709654115, 'champion': 875, 'queue': 420, 'season': 13, 'timestamp': 1594854382037, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4709546735, 'champion': 113, 'queue': 420, 'season': 13, 'timestamp': 1594850792558, 'role': 'DUO_SUPPORT', 'lane': 'TOP'}, {'platformId': 'EUW1', 'gameId': 4706883023, 'champion': 121, 'queue': 420, 'season': 13, 'timestamp': 1594723475884, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4703718275, 'champion': 121, 'queue': 420, 'season': 13, 'timestamp': 1594551535462, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4703411360, 'champion': 245, 'queue': 420, 'season': 13, 'timestamp': 1594509687989, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4703403465, 'champion': 245, 'queue': 420, 'season': 13, 'timestamp': 1594506333259, 'role': 'NONE', 'lane': 'JUNGLE'}]}"""
- #_______________________________________________
- #And yes, this (your initial response) runs perfectly for me.
- txt2 = """{'matches': [{'platformId': 'EUW1', 'gameId': 4728220480, 'champion': 121, 'queue': 420, 'season': 13, 'timestamp': 1595790394190, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4727511119, 'champion': 104, 'queue': 420, 'season': 13, 'timestamp': 1595776780604, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4727366101, 'champion': 121, 'queue': 420, 'season': 13, 'timestamp': 1595774913709, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4724700944, 'champion': 104, 'queue': 420, 'season': 13, 'timestamp': 1595632344294, 'role': 'DUO_SUPPORT', 'lane': 'NONE'}, {'platformId': 'EUW1', 'gameId': 4724662512, 'champion': 163, 'queue': 420, 'season': 13, 'timestamp': 1595629227345, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4724497303, 'champion': 203, 'queue': 420, 'season': 13, 'timestamp': 1595627065458, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4722652071, 'champion': 104, 'queue': 420, 'season': 13, 'timestamp': 1595530253160, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4709654115, 'champion': 875, 'queue': 420, 'season': 13, 'timestamp': 1594854382037, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4709546735, 'champion': 113, 'queue': 420, 'season': 13, 'timestamp': 1594850792558, 'role': 'DUO_SUPPORT', 'lane': 'TOP'}, {'platformId': 'EUW1', 'gameId': 4706883023, 'champion': 121, 'queue': 420, 'season': 13, 'timestamp': 1594723475884, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4703718275, 'champion': 121, 'queue': 420, 'season': 13, 'timestamp': 1594551535462, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4703411360, 'champion': 245, 'queue': 420, 'season': 13, 'timestamp': 1594509687989, 'role': 'NONE', 'lane': 'JUNGLE'}, {'platformId': 'EUW1', 'gameId': 4703403465, 'champion': 245, 'queue': 420, 'season': 13, 'timestamp': 1594506333259, 'role': 'NONE', 'lane': 'JUNGLE'}]}"""
- txt = json.loads(txt2.replace("'", '"'))
- output = [x["gameId"] for x in txt["matches"]]
- print(output)
Add Comment
Please, Sign In to add comment