2

What's the most quickly way to deserialize a Json in PHP? Actual I thought not to use external libraries but to do everything through my code. I downloaded the resource:

$variable = file_get_contents("http://api.football-data.org/alpha/soccerseasons/");
$decoded = json_decode($variable);
var_dump($decoded);

Now I have everything in the variable array decoded, as you advise me to do to get all the values of the json?

UPDATE - DECODED CONTENT:

array(11) { [0]=> object(stdClass)#1 (7) { ["_links"]=> object(stdClass)#2 (4) { ["self"]=> object(stdClass)#3 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/394" } ["teams"]=> object(stdClass)#4 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/394/teams" } ["fixtures"]=> object(stdClass)#5 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/394/fixtures" } ["leagueTable"]=> object(stdClass)#6 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/394/leagueTable" } } ["caption"]=> string(21) "1. Bundesliga 2015/16" ["league"]=> string(3) "BL1" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(18) ["numberOfGames"]=> int(306) ["lastUpdated"]=> string(20) "2015-07-15T05:21:07Z" } [1]=> object(stdClass)#7 (7) { ["_links"]=> object(stdClass)#8 (4) { ["self"]=> object(stdClass)#9 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/395" } ["teams"]=> object(stdClass)#10 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/395/teams" } ["fixtures"]=> object(stdClass)#11 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/395/fixtures" } ["leagueTable"]=> object(stdClass)#12 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/395/leagueTable" } } ["caption"]=> string(21) "2. Bundesliga 2015/16" ["league"]=> string(3) "BL2" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(18) ["numberOfGames"]=> int(306) ["lastUpdated"]=> string(20) "2015-08-03T02:28:27Z" } [2]=> object(stdClass)#13 (7) { ["_links"]=> object(stdClass)#14 (4) { ["self"]=> object(stdClass)#15 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/396" } ["teams"]=> object(stdClass)#16 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/396/teams" } ["fixtures"]=> object(stdClass)#17 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/396/fixtures" } ["leagueTable"]=> object(stdClass)#18 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/396/leagueTable" } } ["caption"]=> string(15) "Ligue 1 2015/16" ["league"]=> string(3) "FL1" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(20) ["numberOfGames"]=> int(380) ["lastUpdated"]=> string(20) "2015-07-31T06:12:34Z" } [3]=> object(stdClass)#19 (7) { ["_links"]=> object(stdClass)#20 (4) { ["self"]=> object(stdClass)#21 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/397" } ["teams"]=> object(stdClass)#22 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/397/teams" } ["fixtures"]=> object(stdClass)#23 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/397/fixtures" } ["leagueTable"]=> object(stdClass)#24 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/397/leagueTable" } } ["caption"]=> string(15) "Ligue 2 2015/16" ["league"]=> string(3) "FL2" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(20) ["numberOfGames"]=> int(380) ["lastUpdated"]=> string(20) "2015-08-02T12:20:09Z" } [4]=> object(stdClass)#25 (7) { ["_links"]=> object(stdClass)#26 (4) { ["self"]=> object(stdClass)#27 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/398" } ["teams"]=> object(stdClass)#28 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/398/teams" } ["fixtures"]=> object(stdClass)#29 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/398/fixtures" } ["leagueTable"]=> object(stdClass)#30 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/398/leagueTable" } } ["caption"]=> string(22) "Premier League 2015/16" ["league"]=> string(2) "PL" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(20) ["numberOfGames"]=> int(380) ["lastUpdated"]=> string(20) "2015-07-31T06:02:18Z" } [5]=> object(stdClass)#31 (7) { ["_links"]=> object(stdClass)#32 (4) { ["self"]=> object(stdClass)#33 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/399" } ["teams"]=> object(stdClass)#34 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/399/teams" } ["fixtures"]=> object(stdClass)#35 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/399/fixtures" } ["leagueTable"]=> object(stdClass)#36 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/399/leagueTable" } } ["caption"]=> string(24) "Primera Division 2015/16" ["league"]=> string(2) "PD" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(20) ["numberOfGames"]=> int(380) ["lastUpdated"]=> string(20) "2015-07-15T05:27:20Z" } [6]=> object(stdClass)#37 (7) { ["_links"]=> object(stdClass)#38 (4) { ["self"]=> object(stdClass)#39 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/400" } ["teams"]=> object(stdClass)#40 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/400/teams" } ["fixtures"]=> object(stdClass)#41 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/400/fixtures" } ["leagueTable"]=> object(stdClass)#42 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/400/leagueTable" } } ["caption"]=> string(24) "Segunda Division 2015/16" ["league"]=> string(2) "SD" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(20) ["numberOfGames"]=> int(420) ["lastUpdated"]=> string(20) "2015-07-19T09:47:33Z" } [7]=> object(stdClass)#43 (7) { ["_links"]=> object(stdClass)#44 (4) { ["self"]=> object(stdClass)#45 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/401" } ["teams"]=> object(stdClass)#46 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/401/teams" } ["fixtures"]=> object(stdClass)#47 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/401/fixtures" } ["leagueTable"]=> object(stdClass)#48 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/401/leagueTable" } } ["caption"]=> string(15) "Serie A 2015/16" ["league"]=> string(2) "SA" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(20) ["numberOfGames"]=> int(380) ["lastUpdated"]=> string(20) "2015-07-31T06:00:43Z" } [8]=> object(stdClass)#49 (7) { ["_links"]=> object(stdClass)#50 (4) { ["self"]=> object(stdClass)#51 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/402" } ["teams"]=> object(stdClass)#52 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/402/teams" } ["fixtures"]=> object(stdClass)#53 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/402/fixtures" } ["leagueTable"]=> object(stdClass)#54 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/402/leagueTable" } } ["caption"]=> string(21) "Primeira Liga 2015/16" ["league"]=> string(3) "PPL" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(18) ["numberOfGames"]=> int(306) ["lastUpdated"]=> string(20) "2015-07-31T06:15:10Z" } [9]=> object(stdClass)#55 (7) { ["_links"]=> object(stdClass)#56 (4) { ["self"]=> object(stdClass)#57 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/403" } ["teams"]=> object(stdClass)#58 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/403/teams" } ["fixtures"]=> object(stdClass)#59 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/403/fixtures" } ["leagueTable"]=> object(stdClass)#60 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/403/leagueTable" } } ["caption"]=> string(21) "3. Bundesliga 2015/16" ["league"]=> string(3) "BL3" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(20) ["numberOfGames"]=> int(380) ["lastUpdated"]=> string(20) "2015-08-03T02:28:50Z" } [10]=> object(stdClass)#61 (7) { ["_links"]=> object(stdClass)#62 (4) { ["self"]=> object(stdClass)#63 (1) { ["href"]=> string(52) "http://api.football-data.org/alpha/soccerseasons/404" } ["teams"]=> object(stdClass)#64 (1) { ["href"]=> string(58) "http://api.football-data.org/alpha/soccerseasons/404/teams" } ["fixtures"]=> object(stdClass)#65 (1) { ["href"]=> string(61) "http://api.football-data.org/alpha/soccerseasons/404/fixtures" } ["leagueTable"]=> object(stdClass)#66 (1) { ["href"]=> string(64) "http://api.football-data.org/alpha/soccerseasons/404/leagueTable" } } ["caption"]=> string(18) "Eredivisie 2015/16" ["league"]=> string(3) "DED" ["year"]=> string(4) "2015" ["numberOfTeams"]=> int(18) ["numberOfGames"]=> int(306) ["lastUpdated"]=> string(20) "2015-08-03T02:34:21Z" } }
Harold Finch
  • 576
  • 11
  • 32

1 Answers1

4

Try

$decoded = json_decode($variable,true);

it should create an array. Easier to use

Alexis
  • 5,681
  • 1
  • 27
  • 44
  • I know how to create an array, I want to know how to get all the objects in the memory array in a simple and fast way. – Harold Finch Aug 03 '15 at 07:26
  • 1
    using true in the function return an array like JSON : '{"a":1,"b":2,"c":3,"d":4,"e":5}'. And array(5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) }. Easy to get the objects no ? – Alexis Aug 03 '15 at 07:28