2012-05-28 58 views
1

我一直陷入試圖解碼一些JSON我從一個數據庫查詢取回:PHP: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了一下,你怎麼這麼快就忘了,這很有趣......

+0

此外,由於您已經離開php:而不是會話,序列化可能會更安全。但是,它確實取決於場景,我看不到足夠的代碼來確定。 – Digitalis

回答

3

你們這樣做是正確的第一次。你只需要繼續這樣做。

echo $thisValue->pageName; 
+0

dang it,嘗試了一切,但我在想別的東西,謝謝... – PruitIgoe