Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP解析pinterest JSON api_Php_Json_Parsing_Pinterest - Fatal编程技术网

用PHP解析pinterest JSON api

用PHP解析pinterest JSON api,php,json,parsing,pinterest,Php,Json,Parsing,Pinterest,嗨,我在解析这个pinterest JSON文件时遇到问题,有什么想法吗?谢谢 $json = file_get_contents('http://pinterestapi.co.uk/jwmoz/boards'); $obj = json_decode($json); foreach($obj->body as $item){ $example = $item[0]->name; echo $example; } $json=file\u get\u

嗨,我在解析这个pinterest JSON文件时遇到问题,有什么想法吗?谢谢

$json = file_get_contents('http://pinterestapi.co.uk/jwmoz/boards'); $obj = json_decode($json); foreach($obj->body as $item){ $example = $item[0]->name; echo $example; } $json=file\u get\u contents('http://pinterestapi.co.uk/jwmoz/boards'); $obj=json_decode($json); foreach($obj->body as$item){ $example=$item[0]->name; 例如,; } { “正文”:[ {“名称”:“JMOZ”, “href”:“http:\/\/pinterest.com\/jwmoz\/jmoz\/”, “管脚数”:17,“cover\u src”:“http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920643849\u 2DcDfCUK\u 222.jpg”, “thumbs_src”: [“http:\/\/media-cache-ec5.pinterest.com\/upload\/82190761920643841\u dZfvCWmE\u t.jpg”, “http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920194573\u aPAbDtHD\u t.jpg”, “http:\/\/media-cache-ec2.pinterest.com\/upload\/82190761920194563\u dQcOIHvQ\u t.jpg”, “http:\/\/media-cache0.pinterest.com\/upload\/82190761920194557\u VSSI2uQB\u t.jpg” ] }, {“名称”:“JMOZ”, “href”:“http:\/\/pinterest.com\/jwmoz\/jmoz\/”, “管脚数”:17,“cover\u src”:“http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920643849\u 2DcDfCUK\u 222.jpg”, “thumbs_src”: [“http:\/\/media-cache-ec5.pinterest.com\/upload\/82190761920643841\u dZfvCWmE\u t.jpg”, “http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920194573\u aPAbDtHD\u t.jpg”, “http:\/\/media-cache-ec2.pinterest.com\/upload\/82190761920194563\u dQcOIHvQ\u t.jpg”, “http:\/\/media-cache0.pinterest.com\/upload\/82190761920194557\u VSSI2uQB\u t.jpg” ] }, {“名称”:“JMOZ”, “href”:“http:\/\/pinterest.com\/jwmoz\/jmoz\/”, “管脚数”:17,“cover\u src”:“http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920643849\u 2DcDfCUK\u 222.jpg”, “thumbs_src”: [“http:\/\/media-cache-ec5.pinterest.com\/upload\/82190761920643841\u dZfvCWmE\u t.jpg”, “http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920194573\u aPAbDtHD\u t.jpg”, “http:\/\/media-cache-ec2.pinterest.com\/upload\/82190761920194563\u dQcOIHvQ\u t.jpg”, “http:\/\/media-cache0.pinterest.com\/upload\/82190761920194557\u VSSI2uQB\u t.jpg” ] }, {“名称”:“测试I\u00f1t\u00ebrn\u00e2ti\u00f4n\u00e0liz\u00e6ti\u00f8n”, “href:“http:\/\/pinterest.com\/jwmoz\/test internationaliztin\/”, “针数”:0, “保护层”:假, “thumbs_src”:错误 }], “元”:{“计数”:11} }
问题似乎在于对$item使用[0]索引

$example = $item[0]->name;
这应该是

$example = $item->name;
要访问缩略图,请尝试

$obj = json_decode($json);
foreach($obj->body as $item){
  echo '<li>' . $item->name . '<ul>';
  if(!empty($item->thumbs_src))
  {
    foreach($item->thumbs_src as $thumbs_src){
      echo '<li>' . $thumbs_src . '</li>';
    }
  }
  echo '</ul></li>';
}
$obj=json\u decode($json);
foreach($obj->body as$item){
回显“
  • ”.$item->name.“
      ”; 如果(!空($item->thumbs\u src)) { foreach($item->thumbs\u src作为$thumbs\u src){ 回显“
    • ”.$thumbs\u src.
    • ”; } } 回音“
  • ”; }
    对不起,我已经编辑了我的答案,问题是$item[0]->name的用法
    $obj = json_decode($json);
    foreach($obj->body as $item){
      echo '<li>' . $item->name . '<ul>';
      if(!empty($item->thumbs_src))
      {
        foreach($item->thumbs_src as $thumbs_src){
          echo '<li>' . $thumbs_src . '</li>';
        }
      }
      echo '</ul></li>';
    }