Jump to content
techker

Json decode URL

Recommended Posts

Posted (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([{&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
 

Edited by techker

Share this post


Link to post
Share on other sites

That was what I was hoping the OP would see.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

hey guys thx for the help.i will test with var dump and see. So its an array....

Share this post


Link to post
Share on other sites
Posted (edited)

The JSON object is in an array. See barand's first post.

Edited by gw1500se

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.