1

我一直在尝试解码一些我从数据库查询中返回的 json:

我的结果=

{"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 一段时间了,有趣的是你这么快就忘记了......

4

1 回答 1

3

你第一次做对了。你只需要继续这样做。

echo $thisValue->pageName;
于 2012-05-28T01:24:50.277 回答