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

asked Mar 1, 2017 at 5:10
2
  • Show your new json value which you want to decode and use in php ... Commented Mar 1, 2017 at 5: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"? Commented Mar 1, 2017 at 5:23

1 Answer 1

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;
}
answered Mar 1, 2017 at 5:48
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This worked perfectly, I really appreciate it

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.