1

I keep getting stuck trying to decode some json I'm getting back from a db query:

My result =

{"queryResults":[{"id":"1","pageName":"home","blurb":"<p>knowInk Publishing is a Media Professional Services firm dedicated to integrating existing publications into the technology of today, introduce the publications of the future and provide traditional services for the print industry.<\/p> \r\n<p>From e-publishing, e-singles, mobile, web and print design and development, printing on demand and our editorial services we can provide a nuts to soup solution to your publishing needs.<\/p>\r\nLearn more about how KI can help you.","imgPath":"images\/img_homepage.jpg"},{"id":"3","pageName":"about","blurb":"This is where the about text would go. ","imgPath":"images\/img_about.jpg"},{"id":"4","pageName":"services","blurb":"This is where we would talk about the services we can provide","imgPath":"images\/img_services.jpg"},{"id":"5","pageName":"marketplace","blurb":"This is where we will discuss our marketplace, where you can buy and sell things","imgPath":"images\/img_marketplace.jpg"}]}

I put the json into a session var and am able to retrieve it. But when I go to dig into it I am getting stuck. Here's my PHP code:

print $_SESSION['basicPageHTML']; //works fine, gives me the json above

$code = json_decode($_SESSION['basicPageHTML']); 
print count($code->queryResults); //this seems right, gives me 4
foreach($code->queryResults as $thisKey => $thisValue) { 
     //I can't do anything here.
}

I've been away from PHP for a bit and it's funny how you forget so quickly...

1
  • Also, since you've been out of the php: Instead of sessions, serialization might be more secure. It does, however, depend on the scenario, I can't see enough of the code to determine. Commented May 28, 2012 at 1:30

1 Answer 1

3

You did it correctly the first time. You just need to continue doing it.

echo $thisValue->pageName;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.