0

Hello friends I am trying reading this json in php but I don´t get to extract the data correctly

I try this and works

echo $jsonencode->extractordata->url;
echo $jsonencode->extractordata->resourceid;

I want to extract information that it is in data array I try this but it doesn´t work It show me error

echo $jsonencode->extractordata->data->group->hora;
htmlpower
  • 169
  • 1
  • 16
  • 3
    Possible duplicate of [How do I extract data from JSON with PHP?](http://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) – Rajdeep Paul Dec 03 '16 at 12:18

2 Answers2

3
$jsonencode->extractorData->data[0]->group[0]->Hora

The "data" property is an array.

sh1da9440
  • 176
  • 4
1

This is the proper way to traverse your JSON:

$json = file_get_contents($url);
$data = json_decode($json);

if (empty($data->extractorData->data)) {
  die("Invalid data\n");
}

foreach ($data->extractorData->data as $d) {
  if (!is_array($d->group) || !is_array($d->group))
    continue;

  foreach ($d->group as $group) {
    if (!isset($group->Hora) || !is_array($group->Hora))
      continue;

    foreach ($group->Hora as $hora) {
      if (!isset($hora->text))
        continue;

      echo "$hora->text\n";
    }
  }
}

Sample Output

01:00 CET
01:30 CET
01:30 CET
02:00 CET
02:30 CET
04:30 CET
...
Ruslan Osmanov
  • 20,486
  • 7
  • 46
  • 60