JSON in Python(/PHP) behandeln...

Navidi

Well-Known Member
#1
Hallo liebe Community, ich hab da eine kleine große Frage :D

Ich habe kürzlich angefangen die API eines Online-spiels zu verwenden, und bekomme die Response immer im JSON-Format. Soweit hat alles gut funktioniert, ich habe nur wenig Daten bekommen:

{"senzaí":{"id":30990242,"name":"SenZaí","profileIconId":631,"summonerLevel":30,"revisionDate":1484083791000}}

und konnte auch recht gut damit umgehen:
Python:
name = responseleague[summid][0]["name"]
name = str(name)
Nur leider hab ich bei anderen Anfragen riesige Datenmengen:

Code:
{"matches":[{"region":"EUW","platformId":"EUW1","matchId":3011786224,"champion":67,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1484081086977,"lane":"BOTTOM","role":"DUO_CARRY"},{"region":"EUW","platformId":"EUW1","matchId":3011716069,"champion":67,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1484078565783,"lane":"BOTTOM","role":"DUO_CARRY"},{"region":"EUW","platformId":"EUW1","matchId":3011438875,"champion":27,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1484066506297,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3011430968,"champion":36,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1484064125131,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3008540710,"champion":18,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483831280544,"lane":"BOTTOM","role":"DUO_CARRY"},{"region":"EUW","platformId":"EUW1","matchId":3007307877,"champion":38,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483789744654,"lane":"MID","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3005309640,"champion":38,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483648709686,"lane":"MID","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3005268082,"champion":34,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483646271728,"lane":"MID","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3005185685,"champion":24,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483642856434,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3005147544,"champion":122,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483641070136,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3005025513,"champion":23,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483637584720,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3004884374,"champion":23,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483634495414,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3004751247,"champion":34,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483630821020,"lane":"MID","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3004289145,"champion":114,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483608501608,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3004306167,"champion":114,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483606009698,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3004223828,"champion":114,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483580162729,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3004179236,"champion":114,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483577378782,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3004014083,"champion":114,"queue":"RANKED_FLEX_SR","season":"PRESEASON2017","timestamp":1483565867626,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3003857251,"champion":121,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483559846791,"lane":"JUNGLE","role":"NONE"},{"region":"EUW","platformId":"EUW1","matchId":3003670488,"champion":114,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483550235328,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3003343566,"champion":114,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483534165904,"lane":"TOP","role":"SOLO"},{"region":"EUW","platformId":"EUW1","matchId":3003237193,"champion":133,"queue":"TEAM_BUILDER_RANKED_SOLO","season":"PRESEASON2017","timestamp":1483531593422,"lane":"TOP","role":"SOLO"},
Und da die Anfänge oft sehr ähnlich sind hab ich keine Ahnung wie ich die voneinander seperieren soll.... Hat da vielleicht jemand ne Idee? Für PHP oder Python (falls es da Unterschiede bei JSON gibt).

Danke schonmal =)
 

Mat

Well-Known Member
c-b Experte
#2
Bei Python bin ich mir nicht so ganz sicher, hast du es mal mit http://php.net/manual/de/function.json-decode.php versucht? Das macht dir richtig schöne assoziative Arrays aus der JSON.

Eine Idee wäre natürlich, die Daten vorab zu filtern, wenn du die alle gar nicht brauchst. Ideal wäre natürlich, wenn dir die API Filteroptionen anbietet, sonst musst du die Daten bei dir filtern.
 
Oben