1

One of my sources for data recently changed how they are providing a json file to me, they added something before the actual output, and I am having trouble getting the values to display on my landing page.

Old json output

string(6596) "[{"id":239,"solution_id":3486," etc...

New json output

string(6614) "{"picker_offers":[{"id":239,"solution_id":3486," etc...

For my landing page I am using the following:

$datastream = json_decode($result);
foreach($datastream as $component) {

$productid = $component->id;

I was able to successfully output the data to php from their old output, but I am not sure how to get around the value "picker_offers" that is being passed as part of the json file, but it isn't part of the actual data to output.

How can I not include that "picker_offers", or what can I do to be able to read the data? With this new output there is an extra curly bracket wrapper called "picker_offers" around the entire output.

Thank you very much

Robert
  • 143
  • 14
  • Show your new json value which you want to decode and use in php ... – Aman Kumar Mar 01 '17 at 05:18
  • For example, if I just want to output "id", my code looks like: $productid = $component->id; - Do I need to do something different to account for the extra wrapper "picker_offers"? – Robert Mar 01 '17 at 05:23

1 Answers1

1

Solution 1 : if you want to remove picker_offers

$datastream = json_decode($result);
$picker_offers = $datastream->picker_offers;
unset($datastream->picker_offers);
$datastream = $picker_offers;
foreach($datastream as $component) {
   $productid = $component->id;
}

Solution 2 : if you don't want to remove picker_offers

$datastream = json_decode($result);
foreach($datastream->picker_offers as $component) {
  $productid = $component->id;
}
Javed Sayyed
  • 149
  • 11