这样解析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으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿