这样解析json为什么没效果?

WBOY
發布: 2016-06-06 20:19:37
原創
1239 人瀏覽過

<code><?php header("Access-Control-Allow-Origin: *");
header('Content-Type: text/html; charset=UTF-8');
$url = 'https://api.instagram.com/v1/users/self/media/recent/?access_token=';
$json = file_get_contents($url);
$provinces = json_decode($json, true);
foreach($provinces as $province){
echo $province["data"]["0"]["images"]["standard_resolution"];
}
?></code>
登入後複製
登入後複製

$json的内容大概是这样的:

<code>{"pagination":{},"meta":{"code":200},"data":[{"attribution":null,"tags":[],"type":"image","location":null,"comments":{"count":0},"filter":"Normal","created_time":"1453516817","link":"https:\/\/www.instagram.com\/p\/BA3XjWMP4ye\/","likes":{"count":0},"images":{"low_resolution":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpf1\/t51.2885-15\/s320x320\/e35\/12547507_218933238449715_1618422633_n.jpg","width":320,"height":320},"thumbnail":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpf1\/t51.2885-15\/s150x150\/e35\/12547507_218933238449715_1618422633_n.jpg","width":150,"height":150},"standard_resolution":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpf1\/t51.2885-15\/s640x640\/sh0.08\/e35\/12547507_218933238449715_1618422633_n.jpg","width":640,"height":640}},"users_in_photo":[],"caption":null,"user_has_liked":false,"id":"1168506212405185694_2231334066","user":{"username":"misery","profile_picture":"https:\/\/scontent.cdninstagram.com\/hphotos-xta1\/t51.2885-19\/10684024_538087799681202_2023427205_a.jpg","id":"2231334066","full_name":"misery"}},{"attribution":null,"tags":[],"type":"image","location":null,"comments":{"count":0},"filter":"Hefe","created_time":"1444533784","link":"https:\/\/www.instagram.com\/p\/8rpxxov48o\/","likes":{"count":2},"images":{"low_resolution":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpt1\/t51.2885-15\/s320x320\/e35\/11910259_421481191371212_1146964092_n.jpg","width":320,"height":320},"thumbnail":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpt1\/t51.2885-15\/s150x150\/e35\/11910259_421481191371212_1146964092_n.jpg","width":150,"height":150},"standard_resolution":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpt1\/t51.2885-15\/s640x640\/sh0.08\/e35\/11910259_421481191371212_1146964092_n.jpg","width":640,"height":640}},"users_in_photo":[],"caption":null,"user_has_liked":false,"id":"1093151075025784616_2231334066","user":{"username":"misery","profile_picture":"https:\/\/scontent.cdninstagram.com\/hphotos-xta1\/t51.2885-19\/10684024_538087799681202_2023427205_a.jpg","id":"2231334066","full_name":"misery"}}]}</code>
登入後複製
登入後複製

回复内容:

<code><?php header("Access-Control-Allow-Origin: *");
header('Content-Type: text/html; charset=UTF-8');
$url = 'https://api.instagram.com/v1/users/self/media/recent/?access_token=';
$json = file_get_contents($url);
$provinces = json_decode($json, true);
foreach($provinces as $province){
echo $province["data"]["0"]["images"]["standard_resolution"];
}
?></code>
登入後複製
登入後複製

$json的内容大概是这样的:

<code>{"pagination":{},"meta":{"code":200},"data":[{"attribution":null,"tags":[],"type":"image","location":null,"comments":{"count":0},"filter":"Normal","created_time":"1453516817","link":"https:\/\/www.instagram.com\/p\/BA3XjWMP4ye\/","likes":{"count":0},"images":{"low_resolution":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpf1\/t51.2885-15\/s320x320\/e35\/12547507_218933238449715_1618422633_n.jpg","width":320,"height":320},"thumbnail":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpf1\/t51.2885-15\/s150x150\/e35\/12547507_218933238449715_1618422633_n.jpg","width":150,"height":150},"standard_resolution":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpf1\/t51.2885-15\/s640x640\/sh0.08\/e35\/12547507_218933238449715_1618422633_n.jpg","width":640,"height":640}},"users_in_photo":[],"caption":null,"user_has_liked":false,"id":"1168506212405185694_2231334066","user":{"username":"misery","profile_picture":"https:\/\/scontent.cdninstagram.com\/hphotos-xta1\/t51.2885-19\/10684024_538087799681202_2023427205_a.jpg","id":"2231334066","full_name":"misery"}},{"attribution":null,"tags":[],"type":"image","location":null,"comments":{"count":0},"filter":"Hefe","created_time":"1444533784","link":"https:\/\/www.instagram.com\/p\/8rpxxov48o\/","likes":{"count":2},"images":{"low_resolution":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpt1\/t51.2885-15\/s320x320\/e35\/11910259_421481191371212_1146964092_n.jpg","width":320,"height":320},"thumbnail":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpt1\/t51.2885-15\/s150x150\/e35\/11910259_421481191371212_1146964092_n.jpg","width":150,"height":150},"standard_resolution":{"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xpt1\/t51.2885-15\/s640x640\/sh0.08\/e35\/11910259_421481191371212_1146964092_n.jpg","width":640,"height":640}},"users_in_photo":[],"caption":null,"user_has_liked":false,"id":"1093151075025784616_2231334066","user":{"username":"misery","profile_picture":"https:\/\/scontent.cdninstagram.com\/hphotos-xta1\/t51.2885-19\/10684024_538087799681202_2023427205_a.jpg","id":"2231334066","full_name":"misery"}}]}</code>
登入後複製
登入後複製

转义而已,对自己问题的补充修改问题详情即可,不要发表在回答区域
这样解析json为什么没效果?

<code><?php $json='your json value';

$obj=json_decode($json);

$data=$obj->data;

foreach($data as $row){
    echo $row->images->standard_resolution->url."<br>";
}</code>
登入後複製

你只用了json_decode来解码,但是输出的时候并没有json_encode啊。 输出的应该只是一堆字符串吧? \是用来转移字符的. \/ 其实输出以后就是/

相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板