php pinterest,使用PHP解析pinterest JSON api

Hi im having problem parsing this pinterest JSON file, any ideas? thanks

嗨我有解決這個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;

}

{

"body":[

{"name":"JMOZ",

"href":"http:\/\/pinterest.com\/jwmoz\/jmoz\/",

"num_of_pins":17,"cover_src":"http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920643849_2DcDfCUK_222.jpg",

"thumbs_src":

["http:\/\/media-cache-ec5.pinterest.com\/upload\/82190761920643841_dZfvCWmE_t.jpg",

"http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920194573_aPAbDtHD_t.jpg",

"http:\/\/media-cache-ec2.pinterest.com\/upload\/82190761920194563_dQcOIHvQ_t.jpg",

"http:\/\/media-cache0.pinterest.com\/upload\/82190761920194557_VSSI2uQB_t.jpg"

]

},

{"name":"JMOZ",

"href":"http:\/\/pinterest.com\/jwmoz\/jmoz\/",

"num_of_pins":17,"cover_src":"http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920643849_2DcDfCUK_222.jpg",

"thumbs_src":

["http:\/\/media-cache-ec5.pinterest.com\/upload\/82190761920643841_dZfvCWmE_t.jpg",

"http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920194573_aPAbDtHD_t.jpg",

"http:\/\/media-cache-ec2.pinterest.com\/upload\/82190761920194563_dQcOIHvQ_t.jpg",

"http:\/\/media-cache0.pinterest.com\/upload\/82190761920194557_VSSI2uQB_t.jpg"

]

},

{"name":"JMOZ",

"href":"http:\/\/pinterest.com\/jwmoz\/jmoz\/",

"num_of_pins":17,"cover_src":"http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920643849_2DcDfCUK_222.jpg",

"thumbs_src":

["http:\/\/media-cache-ec5.pinterest.com\/upload\/82190761920643841_dZfvCWmE_t.jpg",

"http:\/\/media-cache-ec4.pinterest.com\/upload\/82190761920194573_aPAbDtHD_t.jpg",

"http:\/\/media-cache-ec2.pinterest.com\/upload\/82190761920194563_dQcOIHvQ_t.jpg",

"http:\/\/media-cache0.pinterest.com\/upload\/82190761920194557_VSSI2uQB_t.jpg"

]

},

{"name":"test I\u00f1t\u00ebrn\u00e2ti\u00f4n\u00e0liz\u00e6ti\u00f8n",

"href":"http:\/\/pinterest.com\/jwmoz\/test-internationaliztin\/",

"num_of_pins":0,

"cover_src":false,

"thumbs_src":false

}],

"meta":{"count":11}

}

1 个解决方案

#1

0

It seems the problem is in your usage of the [0] index on $item

似乎問題在於你在$ item上使用[0]索引

$example = $item[0]->name;

This should just be

這應該是

$example = $item->name;

To access the thumbnails, try

要訪問縮略圖,請嘗試

$obj = json_decode($json);

foreach($obj->body as $item){

echo '

' . $item->name . '
  • ';

if(!empty($item->thumbs_src))

{

foreach($item->thumbs_src as $thumbs_src){

echo '

' . $thumbs_src . '';

}

}

echo '

';

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值