【问题标题】:JSON to PHP using file_get_contents don't working使用 file_get_contents 的 JSON 到 PHP 不起作用
【发布时间】:2020-03-27 17:23:56
【问题描述】:

我的 api json

{"success":true,"result":{"id":"1017fw436","title":"Leading with NLP","author":"David","url":"abc.com","image":"/abc.img","info":{"pages":"258 Pages","year":"2001","size":"2.74 MB","downloads":"151,185 Downloads","language":"English"},"url_url":"https://drive.google.com/file/d/1GDA9N9SQLHdXBKih8c_GEwcUL"}}

我用过

    <?php $json_url = "my link api";
$json = file_get_contents($json_url);
$data = json_decode($json, TRUE);
echo $data['id'];
?>

但它不起作用

【问题讨论】:

  • 如果你的意思是 id 没有被回显,那么你需要使用指令 $data['result']['id']
  • 或者有时,您的 PHP 服务器可能无法向您的 API 发出正确的请求(主要是因为 https 客户端验证)。请查看您的错误日志以了解更多详细信息。

标签: php json


【解决方案1】:

请查看Link

试试这行代码:

file_get_contents("http://example.com", false, ['ignore_errors' => true]);
var_dump($http_response_header);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-30
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 2021-08-12
    • 2014-01-14
    • 2012-03-20
    相关资源
    最近更新 更多