我一直在试图解码一些json,我从db查询中回来了:
我的结果=
{"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"}]}
我将json放入会话var并且能够检索它。但是当我去挖掘它时,我会陷入困境。这是我的PHP代码:
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.
}
我已经远离PHP了一点,你很快忘记了这很有趣......
答案 0 :(得分:3)
你第一次就做对了。你只需要继续这样做。
echo $thisValue->pageName;