简体   繁体   English

如何使用foreach循环json_decode?`

[英]How do I loop through a json_decode with foreach?`

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] => 
        )

I have an array like that, but I don't know how to parse through it. 我有一个这样的数组,但我不知道如何解析它。 How do I do, "foreach 0, 1, 2, 3, etc. get href"? 我该怎么办,“foreach 0,1,2,3等获得href”?

Use json_decode with option TRUE to return your result set as an array, then loop through the array. 使用带有选项TRUE的json_decode将结果集作为数组返回,然后遍历数组。

$data = json_decode($my_array, TRUE);

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

You can do 你可以做

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM