php - 试图从 URL 中提取 json,但不起作用
问题描述
我正在尝试从 PHP 中的 URL 中提取产品的 json 文件。我有以下代码,但它不工作。有人可以告诉我哪里出错了吗?
function getJson() {
$request = file_get_contents('https://3rdParty.guntrader.uk/ShootingSuppliesLtd/jsonGuns');
$json = json_decode($request);
return $json;
};
echo $json;
未定义的变量:第 36 行 C:\Users\darry\dev\VVV\www\ssheadless\importJson.php 中的 json
解决方案
你没有调用方法getJson()
。如果不调用方法,则无法访问返回值。调用方法。
function getJson() {
$request = file_get_contents('https://3rdParty.guntrader.uk/ShootingSuppliesLtd/jsonGuns');
$json = json_decode($request);
return $json;
};
echo getJson();
推荐阅读
- python - Docker swarm 服务到服务调用
- html - 为什么我的 CSS 样式没有正确应用?
- android - 如何使用 XML 为 backgroundTint 设置动画?
- java - 无法理解重载的超级调用
- javascript - 使用嵌套回调设置 js 模块的属性
- react-native - 无法使用代理
- bootstrap-4 - 带有多列幻灯片的 Bootstrap 4 Carousel
- c++ - 如何在用户按下空格之前继续输入?
- asp.net-mvc - 当前上下文错误VS2017中不存在名称'Url'
- javascript - 测试异步 SQS sendMessage