{
"data": {
"teamStanding": [
{
"id": "team_1",
"score": 103,
"players": [
{
"user": {
"name": "player_1",
"id": "player_1"
},
"score": 35
. . .
path = 'test.json'
with open(path, 'r') as file:
read_file = file.read()
data = json.loads(read_file)
for teams in data["data"]:
for team in teams['teamStanding']:
for MyTeam in team["id"]:
if MyTeam["id"] == "team_1":
print(MyTeam["players"])
TypeError: string indices must be integers, not 'str'
TypeError: string indices must be integers, not 'str'
{
"data": {
"teamStanding": [
{
"id": "team_1",
"score": 103,
"players": [
{
"user": {
"name": "player_1",
"id": "player_1"
},
"score": 35
},
{
"user": {
"name": "player_2",
"id": "player_2"
},
"score": 30
}
// и так далее...
]
},
// Другие команды...
]
}
}
import json
path = 'test.json'
with open(path, 'r') as file:
data = json.load(file)
for team in data["data"]["teamStanding"]:
if team["id"] == "team_1":
for player in team["players"]:
print(player["user"]["name"], player["score"])