Show data from json

Asked

Viewed 543 times

0

I need to recover the POINTS and RODADA_ATUAL data

The json link is --> https://api.cartolafc.globo.com/time/slug/semtitulos

That’s the name of the team I want to pull the dice on: semtitulos

When you access this url appears all the data of the team, but I can’t get the 2 values I need and print on the screen, I tried as follows:

<?php

// EM file_get_contents

    $url = "https://api.cartolafc.globo.com/time/slug/semtitulos";

    $options = array(
        'http' => 
          array(
            'method' => 'GET', 
            'user_agent' => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)', 
            'timeout' => 1
            )
    );

    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);
    $jogadores = json_decode($response, true);    


    $jogadores['atletas']['pontos'];
    $jogadores['atletas']['rodada_atual'];

     echo $jogadores;

?>

But no result objected, but I use the same scheme above to list the most scaled players --> https://api.cartolafc.globo.com/mercado/destaques and works normally. Someone can help ???

  • Removes the index ['atletas'], leaves so: $jogadores['pontos']; and $jogadores['rodada_atual'];

  • 1

    Thank you Junior :)

  • I created an answer just to make it official!!

1 answer

0


Just take out the athletes index since this information is coming at the root of json:

$pontos = $jogadores['pontos'];
$rodada = $jogadores['rodada_atual'];

Jsonformatter is a good site for you to better analyze the structure of JSON.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.