I do a price parser and other information from the site. Here is a link to all this info: https://loot.farm/fullprice.json

Here is my code:

<?php set_time_limit(300); $urljson = file_get_contents("http://loot.farm/fullprice.json"); $data = json_decode($urljson)->price; echo $data; ?> 

Tell me, what's the problem? I already did a parser for another site, everything was clearer there. Seen once an array, 2 array, etc.

  • Array and Object are different things, before inserting into json_decode you even tried to check what data goes to you? var_dump ($ urljson) - Arsen

1 answer 1

Because json_decode($urljson) is not an object, but an array. It should be like this:

 $data = json_decode($urljson); foreach($data as $obj) { echo $obj->price.'<br>'; } 
  • I think it is worth removing the appeal to the price property from the first line .. - vp_arth
  • And why foreach and $ obj? - 6o6ep
  • @vp_arth, hurried and confused ... and not only in this place. Now the rules should be. - Alexander Belinsky
  • @ 6o6ep, corrected - look at the last option. foreach - because you get not a single object with properties, but a whole array of objects with properties. - Alexander Belinsky
  • THX. Now works. I just last time made a pure copy-test. And now at least figured out - 6o6ep