大家好,我需要一些帮助编辑基于该网站一个API范围网址这样的范围,如果我有foo.com/?Wab_id=15将编辑API范围编辑API URL
?scope=accepted&view=films&wab_id=15
我想我可以有一些像
$ApiData = file_get_contents('http://foo.com/api/?scope=accepted&view=films/&wab_id=$id');
,然后利用获取检索ID这就是被传递到URL编辑API的URL。我也尝试循环虽然整个JSON,然后调用数组内的一个关键,但也没有获得太多的运气我的代码如下
$ApiData = file_get_contents('http://foo.com/api/?scope=accepted&view=films');
$obj = json_decode($ApiData, true);
$data = $obj;
//here you load $data with whatever you want.
$id = $_GET['id'];
foreach ($data[$id] as $key=>$value){
echo "$key -> $value<br>";
}
?>
但这返回一个错误
Invalid argument supplied for foreach()
IVE还试图通过穆蒂阵列一个foreach循环一个foreach的内侧和已经显示的值的代码和结果如下
$obj = json_decode($ApiData, true);
$data = $obj;
//here you load $data with whatever you want.
foreach ($data as $film){
foreach ($film as $key=>$val){
echo "$key -> $val<br>";
}
}
结果
uid -> 95
wab_id -> 95
title -> La Batalla de los Invisibles
title_en -> Battle of the Invisibles
syn_sm ->
syn_med ->
syn_lg ->
form ->
genre ->
language ->
subtitle_lang ->
year ->
runtime ->
place_sub_city ->
place_sub_state ->
place_sub_country ->
place_film_country -> Mexico
place_dir_city ->
place_dir_state ->
place_dir_country ->
accepted -> 1
festival_year -> 2014
trailer ->
links ->
我不知道你问什么,但可以肯定的循环int是不是一个好主意。此外,最好使用CURL而不是file_get_contents()来检索网站内容 – Robert 2015-02-10 23:53:09
这可能是因为你没有设置$ data [95]。 – Darren 2015-02-11 00:03:54
您是否将'wab_id','Wab_id'或'id'传递到您要使用'$ _GET'访问的服务器?因为它不清楚你将自己传递给自己的关键在哪里,如果你使用的是正确的关键 - 这可能是你现在遇到的问题。 – prodigitalson 2015-02-11 00:11:43