Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从Google Financials解码JSON_Php_Json_Api - Fatal编程技术网

Php 从Google Financials解码JSON

Php 从Google Financials解码JSON,php,json,api,Php,Json,Api,我知道Google Financials已经停产,但我发现这个链接仍在运行,并且正在做我需要的事情: 现在它显然返回了一个名为f.txt的文件,我不知道如何通过PHP读取该文件。我试过这个: $url = "https://finance.google.com/finance?q=NYSE:CLNS-D&output=json" $json = file_get_contents($url); $json_data

我知道Google Financials已经停产,但我发现这个链接仍在运行,并且正在做我需要的事情:

现在它显然返回了一个名为f.txt的文件,我不知道如何通过PHP读取该文件。我试过这个:

            $url = "https://finance.google.com/finance?q=NYSE:CLNS-D&output=json"
            $json = file_get_contents($url);
            $json_data = json_decode($json, true);
            var_dump($json_data);
但这对我不起作用。var_转储的返回值仅为NULL

有谁能指导我能够与这个f.txt文件交互,并能在我的html中显示其中的数据吗


谢谢

无论如何,我都不是JSON专家,但看起来你从谷歌检索的数据中有几个看起来不“标准”的前导字符。解决问题的方法是:

$url = "https://finance.google.com/finance?q=NYSE:CLNS-D&output=json";

$request = file_get_contents($url);
$data = substr($request, 4);
$json = json_decode($data, 1);

var_dump($json);

您的代码缺少错误检查。此外,您应该在发布之前提取MCVE。相反,here.var\u dumping$json显示它包含的内容以换行符开始,
/[
,换行符,
{…
-所以它显然不是json。@CBroe哦,你是说来自Google的f.txt文件不是json格式的?