URL isn't returning valid JSON.
你能做一个$ json = file_get_contents($ url); 在已使用$ json = file_get_contents($ url);的foreach语句中? [关闭]
$url = "www.test.com"
$json = file_get_contents($url);
$data = json_decode($json);
foreach($data as $mydata) {
$id = $mydata->id;
$url2 = "www.test.com/$id";
$json2 = file_get_contents($url2);
$data2 = json_decode($json2);
var_dump($data2); // seems to always be null?? :(
foreach($data2 as $mydata2) {
.............
}
}
the error I get is Warning: Invalid argument supplied for foreach() which is because data2 is not an array....
Guessing I can't do file_get_contents() stacked like I am. Is there a way around this?
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
2条回答
为你推荐
- 循环一个file_get_contents直到在php中获得非空的JSON
- loops
- php
- 1个回答
- 你能做一个$ json = file_get_contents($ url); 在已使用$ json = file_get_contents($ url);的foreach语句中? [关闭]
- php
- foreach
- 2个回答
- Apache服务器中未定义File_get_contents错误
- apache
- apache
- php
- json
- 1个回答
- php中的json_decode用于web服务url(url给出数据)
- php
- 2个回答
- 来自多个URL的'file_get_contents'函数和重定向限制已达到警告
- decode
- url
- php
- json
- 1个回答
- PHP:使用file_get_contents的大量请求
- api
- php
- mysql
- 1个回答
- 为什么这个file_get_contents()有时工作,有时不工作?
- youtube
- api
- php
- 1个回答
- 从PHP中的JSON解码数据中提取FIRST结果
- php
- arrays
- json
- 2个回答
- PHP file_get_contents提供HTTP代码401 Unauthorized
- php
- 1个回答
- 无法使用file_get_contents()以正确的格式获取json
- php
- json
- 4个回答
- file_get_contents返回400 Bad Request
- php
- 2个回答
- file_get_contents()无法获取数据?
- php
- json
- 3个回答
- 从file_get_contents转换为wp_remote_get
- php
- json
- wordpress
- 2个回答
- 需要帮助在wordpress网站上缓存json_decode(file_get_contents('api'))
- php
- 1个回答
- 从外部URL获取数据时,file_get_contents是否算作综合浏览量?
- google-analytics
- php
- 1个回答
- file_get_contents无法从正确的url中检索html
- php
- 1个回答
- PHP:file_get_contents()强制从服务器而不是缓存中读取文件
- php
- 3个回答
- 使用file_get_contents从url获取JSON
- php
- json
- 3个回答
- 为什么json_decode($ data,TRUE)将数组转换为字符串?
- php
- javascript
- json
- 1个回答
- 使用浏览器打开URL并且URL有效时,file_get_contents返回404
- url
- php
- json
- 1个回答