Jump to content

Json decode URL


techker

Recommended Posts

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([{&quot;id&quot;:&quot;1&quot;,&quot;package_name&quot;:&quot;1 Month Full + Adult - 2 Devices&quot;,&quot;is_trial&quot;:&quot;0&quot;,&quot;is_official&quot;:&quot;1&quot;,&quot;trial_credits&quot;:&quot;0&quot;,&quot;official_credits&quot;:&quot;1&quot;,&quot;trial_duration&quot;:&quot;24&quot;,&quot;trial_duration_in&quot;:&quot;hours&quot;,&quot;official_duration&quot;:&quot;1&quot;,&quot;official_duration_in&quot;:&quot;months&quot;,&quot;groups&quot;:&quot;[4,5,6,8]&quot;,&quot;bouquets&quot;:&quot;[27]&quot;,&quot;can_gen_mag&quot;:&quot;1&quot;,&quot;only_mag&quot;:&quot;0&quot;,&quot;output_formats&quot;:&quot;[1,2,3]&quot;,&quot;is_isplock&quot;:&quot;0&quot;,&quot;max_connections&quot;:&quot;2&quot;,&quot;is_restreamer&quot;:&quot;0&quot;,&quot;force_server_id&quot;:&quot;0&quot;,&quot;can_gen_e2&quot;:&quot;1&quot;,&quot;only_e2&quot;:&quot;0&quot;,&quot;forced_country&quot;:&quot;&quot;,&quot;lock_device&quot;:&quot;0&quot;},{&quot;id&quot;:&quot;2&quot;,&quot;package_name&quot in /home/handshak/public_html/XC/get2.php on line 7
 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.