1

i have url with this simple JSON {"result":true,"data":[{"Position":"135"}]}

I tried to read it with this:

$json = file_get_contents('https://...link/here..');
$obj = json_decode($json);
echo $obj->result[1]->data->Position;

but it not works. Where i do a mistake? Thanks for helping!

Powering
  • 39
  • 1
  • 4

1 Answers1

2

You are incorrectly addressing the data in the PHP object created from the JSON String

$json = file_get_contents('https://...link/here..');
$obj = json_decode($json);
echo $obj->data[0]->Position;

Or if there are more occurances

foreach ( $obj->data as $idx=>$data) {
    echo $data->Position;
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Very accurate answer, but how can we implement load more function? for example, if we have 1000 more data how can we split to show 15 each and then show load more button to click and show another 15 so on... til we reach the end of the data – amprie286 Sep 28 '20 at 06:44
  • 1
    @amprie286 That sounds like Pagination. There are lots of tutorials out there on that subject – RiggsFolly Sep 28 '20 at 09:43