Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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 如何将数据从url获取到数组?_Php_Arrays_Get - Fatal编程技术网

Php 如何将数据从url获取到数组?

Php 如何将数据从url获取到数组?,php,arrays,get,Php,Arrays,Get,我对php的使用非常糟糕。我不是一个程序员,只是为我的私事做些事情。 我有这样一个问题,我想从我的光伏生产下载数据。数据格式如下所示。如何分别从php中的url下载数据,将它们分组并发送到数组?? 提前感谢您的帮助 {“sid”:62923,“数据单位”:“kWh”,“数据”:[{“时间”:“2019-08-01”,“否”:“1”,“值”:“27.7”},{“时间”:“2019-08-02”,“否”:“2”,“值”:“24.0”},{“时间”:“2019-08-03”,“否”:“3”,“值”:“

我对php的使用非常糟糕。我不是一个程序员,只是为我的私事做些事情。 我有这样一个问题,我想从我的光伏生产下载数据。数据格式如下所示。如何分别从php中的url下载数据,将它们分组并发送到数组?? 提前感谢您的帮助

{“sid”:62923,“数据单位”:“kWh”,“数据”:[{“时间”:“2019-08-01”,“否”:“1”,“值”:“27.7”},{“时间”:“2019-08-02”,“否”:“2”,“值”:“24.0”},{“时间”:“2019-08-03”,“否”:“3”,“值”:“19.9”},{“时间”:“2019-08-04”,“否”:“4”,“值”:“25.3”},{“时间”:“2019-08-05”,“否”:“5”,“值”:“0.0”},{“时间”:“2019-08-06”,“值”:“0.07”{,“价值”:“0.0.0”价值“2019-08-15,“否”:“值”:“0.0”}、{“时间”:“2019-08-16”、“否”:“16”、“值”:“0.0”}、{“时间”:“2019-08-17”、“否”:“17”、“值”:“0.0”}、{“时间”:“2019-08-18”、“否”:“18”、“值”:“0.0”}、{“时间”:“2019-08-19”、“否”:“19”、“值”:“0.0”}、{“时间”:“2019-08-20”、“否”:“值”:“0.0.0”}、{“时间”:“21”、“值”:“0.22”{值:“:”0.0“},{”时间:“:”2019-08-23”,“否:”,“23”,“值:”,““0.0”},{”时间:“:”2019-08-25”,“否:”,”25”,“值:“:”0.0“},{”时间:“:”2019-08-26”,“否:”,“26”,“值:“:”0.0“},{”时间:“,“,”2019-08-27”,“否:”,“值:“:”0.0“{”,时间:“:”2019-08-28”,“否”时间:“,”0.0-29”,“值:{”2019-08-30,“否”:“30”,“值”:“0.0”},{“时间”:“2019-08-31”,“否”:“31”,“值”:“0.0”}]}

试试这个

<?php 

$json_url = file_get_contents('Your url goes here');
$data = json_decode($json_url,true);

var_dump($data);
// You can print all of your data here to see if it works
foreach ($data as $items) {
    // You can loop trough the data and get it like $items->sid etc
    var_dump($items);
}

?>

您需要使用“file\u get\u contents”获取URL,然后使用json\u decode对其进行解码

然后用for-each函数打印出来

试试这个

<?php 

$json_url = file_get_contents('Your url goes here');
$data = json_decode($json_url,true);

var_dump($data);
// You can print all of your data here to see if it works
foreach ($data as $items) {
    // You can loop trough the data and get it like $items->sid etc
    var_dump($items);
}

?>

您需要使用“file\u get\u contents”获取URL,然后使用json\u decode对其进行解码


然后用for each function

read about function json_decode()打印出来,看起来你得到了一个json格式的数据,所以你需要使用json_decode();read about function json_decode()的可能副本好像你得到了一个json格式的数据,所以你需要使用json_decode();Thx的可能副本可以工作,但$data=json_decode($json,true);-->$data=json_decode($json_url,true);)Thx可以工作,但$data=json_decode($json,true);-->$data=json_decode($json_url,true);)