techker Posted April 14, 2019 Share Posted April 14, 2019 (edited) Hey guys i got an api and it returns : [ { "id":"1", "package_name":"1 Month Full + Adult - 2 Devices", "is_trial":"0", "is_official":"1", "trial_credits":"0", "official_credits":"1", "trial_duration":"24", "trial_duration_in":"hours", "official_duration":"1", "official_duration_in":"months", "groups":"[4,5,6,8]", "bouquets":"[27]", "can_gen_mag":"1", "only_mag":"0", "output_formats":"[1,2,3]", "is_isplock":"0", "max_connections":"2", "is_restreamer":"0", "force_server_id":"0", "can_gen_e2":"1", "only_e2":"0", "forced_country":"", "lock_device":"0" },......] $json = file_get_contents(URL); $data = json_decode($json,true); $Decoded = $data['id'][0]; HERE no mater what i put i get and error Undefined index: id in /home/handshak/public_html/XC/get2.php on line 9 echo "<pre>"; print_r($Decoded); exit; What type of json structure is that? EDIT: if i use: $contents = file_get_contents($json); $contents = utf8_encode($contents); $results = json_decode($contents); i get: [14-Apr-2019 15:38:32 UTC] PHP Warning: file_get_contents([{"id":"1","package_name":"1 Month Full + Adult - 2 Devices","is_trial":"0","is_official":"1","trial_credits":"0","official_credits":"1","trial_duration":"24","trial_duration_in":"hours","official_duration":"1","official_duration_in":"months","groups":"[4,5,6,8]","bouquets":"[27]","can_gen_mag":"1","only_mag":"0","output_formats":"[1,2,3]","is_isplock":"0","max_connections":"2","is_restreamer":"0","force_server_id":"0","can_gen_e2":"1","only_e2":"0","forced_country":"","lock_device":"0"},{"id":"2","package_name" in /home/handshak/public_html/XC/get2.php on line 7 Edited April 14, 2019 by techker Quote Link to comment Share on other sites More sharing options...
gw1500se Posted April 14, 2019 Share Posted April 14, 2019 print_r will print an array. Instead use 'var_dump' and you will see exactly what it is. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 14, 2019 Share Posted April 14, 2019 Did you try echo $data[0]['id']; Quote Link to comment Share on other sites More sharing options...
gw1500se Posted April 14, 2019 Share Posted April 14, 2019 That was what I was hoping the OP would see. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 14, 2019 Share Posted April 14, 2019 When I decoded and used print_r I got this $data Array ( [0] => Array ( [id] => 1 [package_name] => 1 Month Full + Adult - 2 Devices [is_trial] => 0 [is_official] => 1 [trial_credits] => 0 [official_credits] => 1 [trial_duration] => 24 [trial_duration_in] => hours [official_duration] => 1 [official_duration_in] => months [groups] => [4,5,6,8] [bouquets] => [27] [can_gen_mag] => 1 [only_mag] => 0 [output_formats] => [1,2,3] [is_isplock] => 0 [max_connections] => 2 [is_restreamer] => 0 [force_server_id] => 0 [can_gen_e2] => 1 [only_e2] => 0 [forced_country] => [lock_device] => 0 ) ) If he didn't see it there it's unlikely a var_dump would have clarified things Quote Link to comment Share on other sites More sharing options...
techker Posted April 15, 2019 Author Share Posted April 15, 2019 hey guys thx for the help.i will test with var dump and see. So its an array.... Quote Link to comment Share on other sites More sharing options...
gw1500se Posted April 15, 2019 Share Posted April 15, 2019 (edited) The JSON object is in an array. See barand's first post. Edited April 15, 2019 by gw1500se Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.