3
  <?php

  $data='{
  "id": "621805046", 
  "likes": {
    "data": [
      {
        "category": "Movie", 
        "name": "Pyaar Ka PUNCHnama", 
        "created_time": "2013-08-13T10:11:23+0000", 
        "id": "151480271575584"
      }, 
      {
        "category": "Company", 
        "name": "Ardent Architects", 
        "created_time": "2013-08-05T09:06:43+0000", 
        "id": "208530229271384"
      }, 
      {
        "category": "School", 
        "name": "APS Confessions", 
        "created_time": "2013-08-04T04:02:28+0000", 
        "id": "349865055122777"
      }, 
      {
        "category": "Education", 
        "category_list": [
          {
            "id": "151676848220295", 
            "name": "Education"
          }
        ], 
        "name": "Adhyan", 
        "created_time": "2013-07-31T17:56:58+0000", 
        "id": "165231053638461"
      }, 
      {
        "category": "Community", 
        "name": "Wallpapers", 
        "created_time": "2013-07-23T18:35:59+0000", 
        "id": "164958583664617"
      }, 
      {
        "category": "Software", 
        "name": "Hill Climb Racing", 
        "created_time": "2013-07-17T05:28:31+0000", 
        "id": "401178656621800"
      }, 
      {
        "category": "Games/toys", 
        "name": "Hill Climb Racing", 
        "created_time": "2013-07-17T05:28:18+0000", 
        "id": "431491673581713"
      }, 
      {
        "category": "Public figure", 
        "name": "Aanya Kaul", 
        "created_time": "2013-07-16T05:12:50+0000", 
        "id": "176616425843752"
      }
    ]
}
}'; 



    $values = json_decode($data,true);
       foreach ($values as $value=>$vv){


foreach($vv as $v1=>$v2){
foreach($v2 as $v4=>$v3){
 $g=count($v2);
        $fields=array();
foreach($v3 as $v7=>$v8){
if($g++!=0) 
        $v7 = $v7;
        $v8 = mysql_real_escape_string($v8);
        $fields[] .= "'$v8'";
        }
 echo $fields = implode(" , ", $fields); 
      ?>

当我回显 $fields 时,它只是向我显示 -:

**“电影”、“Pyaar Ka PUNCHnama”、“2013-08-13T10:11:23+0000”、“151480271575584”、“公司”、“Ardent Architects”、“2013-08-05T09:06:43+ 0000','208530229271384','学校','APS自白','2013-08-04T04:02:28 + 0000','349865055122777','教育','','Adhyan','2013-07- 31T17:56:58+0000' , '165231053638461**

我不明白为什么会这样。我得到了第一个三个数组,但之后它就停止了。

4

1 回答 1

1
$res = json_decode($str,true);

           /*echo "<pre>";
           print_r($res);
           echo "</pre>";*/
           $res = $res['likes']['data'];
           for ($i=0; $i < count($res); $i++){
                echo $res[$i]['category'] . " | " . $res[$i]['name'] . " | " . $res[$i]['created_time'] . " | " . $res[$i]['id'] ;
                if (array_key_exists("category_list",$res[$i])) {
                    $cl = $res[$i]['category_list'];
                    echo " | ";
                    foreach($cl as $icl) {
                        echo $icl['name'].",";
                    }
                }
                echo "<hr />";

}

于 2013-08-24T13:21:47.227 回答