2013-04-10 26 views
0
Array 
(
    [0] => stdClass Object 
     (
      [href] => http://www.google.com 
      [description] => search 
      [extended] => 
      [meta] => x 
      [hash] => x 
      [time] => 2013-04-09T02:00:57Z 
      [shared] => yes 
      [toread] => no 
      [tags] => 
     ) 

    [1] => stdClass Object 
     (
      [href] => http://shop.frankchimero.com/collections/frontpage/products/the-shape-of-design-digital-preorder 
      [description] => 
      [extended] => 
      [meta] => x 
      [hash] => x 
      [time] => 2013-04-06T19:39:51Z 
      [shared] => yes 
      [toread] => no 
      [tags] => 
     ) 

我有一個這樣的數組,但我不知道如何解析它。我該怎麼做,「foreach 0,1,2,3等獲得href」?如何通過一個json_decode循環與foreach?

回答

2

使用json_decode與選項TRUE返回結果集爲一個數組,然後通過數組循環。

$data = json_decode($my_array, TRUE); 

foreach($data as $info) { 
    echo $info['href']; 
    echo $info['time']; 
    //etc.. 
} 
0

你可以做

foreach($yourJSONArrayName as $jsonObject) 
{ 
    echo $jsonObject->href; //etc 
//print_r($jsonObject); 
} 
0
foreach ($jsonPages as $page) 
{ 
    var_dump($page->href); 
}