1

I have following code

$array_store='maxbounty/maxBounty.json';
$test = $array_store->return[0]->entries[1]->value;
echo $test;

Here the file maxBounty.json has following format.

stdClass Object ( [return] => Array 
( [0] => stdClass Object ( [entries] => Array 
( [0] => stdClass Object ( [key] => LAUNCH_DATE [value] => 2017/02/10 )
 [1] => stdClass Object ( [key] => COUNTRIES [value] => US ) 
[2] => stdClass Object ( [key] => CONTEXTUAL_TRAFFIC_ALLOWED [value] => Y )... and so on

But i am getting following error

Notice: Trying to get property of non-object in C:\wamp\www\couponcactusapis\test2.php on line 5

How can i print the value of LAUNCH_DATE , COUNTRIES and CONTEXTUAL_TRAFFIC_ALLOWED ?

Any idea please. THANKS.

  • 1
    You didn't read the file, you just put its name in a string literal. And if that is the content of the file, its not JSON, and if it was you didn't run a `json_decode()` on it. – RiggsFolly Feb 13 '17 at 09:00
  • You are telling php the json string as a file path. You will need to read and parse the file before you can even decode it. And only then you will be able to get an instance of your object. See this question => http://stackoverflow.com/questions/4343596/parsing-json-file-with-php – Louis Loudog Trottier Feb 13 '17 at 09:00
  • How did you create that file? – RiggsFolly Feb 13 '17 at 09:05
  • Who upvotes questions like this. _Please stop it, it is not helpful, and nobody is fooled for long_ – RiggsFolly Feb 13 '17 at 12:17
  • Thanks for replies and sorry i hav updated my code with this . return[0]->entries[1]->value; echo $test; ?> But am getting the same error. Thanks – Wajahat Dar Feb 14 '17 at 06:01

0 Answers0