通过PHP从URL获取JSON [英] Get JSON from URL by PHP
本文介绍了通过PHP从URL获取JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个返回如下JSON对象的URL:
I have a URL that returns a JSON object like this:
[
{
"idIMDB": "tt0111161",
"ranking": 1,
"rating": "9.2",
"title": "The Shawshank Redemption",
"urlPoster": "http:\/\/ia.media-imdb.com\/images\/M\/MV5BODU4MjU4NjIwNl5BMl5BanBnXkFtZTgwMDU2MjEyMDE@._V1_UX34_CR0,0,34,50_AL_.jpg",
"year": "1994"
}
]
URL: http://www.myapifilms.com/imdb/top
我想获取所有urlPoster
值并设置数组的元素,然后将数组转换为JSON,以便对其进行回显.
I want to get all of the urlPoster
value and set in a array's element, and convert array to JSON so echo it.
如何通过PHP做到这一点?
How can I do it through PHP?
推荐答案
$json = file_get_contents('http://www.myapifilms.com/imdb/top');
$array = json_decode($json);
$urlPoster=array();
foreach ($array as $value) {
$urlPoster[]=$value->urlPoster;
}
print_r($urlPoster);
这篇关于通过PHP从URL获取JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文