0

I use php pretty badly. I'm not a programmer just doing something for my private things. I have such a problem I would like to download data from my PV production. The data is in the form as below. How to download data from a url in php, respectively, to group them and send them to the array ?? Thank you in advance for all your help.

{"sid":62923,"dataunit":"kWh","data":[{"time":"2019-08-01","no":"1","value":"27.7"},{"time":"2019-08-02","no":"2","value":"24.0"},{"time":"2019-08-03","no":"3","value":"19.9"},{"time":"2019-08-04","no":"4","value":"25.3"},{"time":"2019-08-05","no":"5","value":"0.0"},{"time":"2019-08-06","no":"6","value":"0.0"},{"time":"2019-08-07","no":"7","value":"0.0"},{"time":"2019-08-08","no":"8","value":"0.0"},{"time":"2019-08-09","no":"9","value":"0.0"},{"time":"2019-08-10","no":"10","value":"0.0"},{"time":"2019-08-11","no":"11","value":"0.0"},{"time":"2019-08-12","no":"12","value":"0.0"},{"time":"2019-08-13","no":"13","value":"0.0"},{"time":"2019-08-14","no":"14","value":"0.0"},{"time":"2019-08-15","no":"15","value":"0.0"},{"time":"2019-08-16","no":"16","value":"0.0"},{"time":"2019-08-17","no":"17","value":"0.0"},{"time":"2019-08-18","no":"18","value":"0.0"},{"time":"2019-08-19","no":"19","value":"0.0"},{"time":"2019-08-20","no":"20","value":"0.0"},{"time":"2019-08-21","no":"21","value":"0.0"},{"time":"2019-08-22","no":"22","value":"0.0"},{"time":"2019-08-23","no":"23","value":"0.0"},{"time":"2019-08-24","no":"24","value":"0.0"},{"time":"2019-08-25","no":"25","value":"0.0"},{"time":"2019-08-26","no":"26","value":"0.0"},{"time":"2019-08-27","no":"27","value":"0.0"},{"time":"2019-08-28","no":"28","value":"0.0"},{"time":"2019-08-29","no":"29","value":"0.0"},{"time":"2019-08-30","no":"30","value":"0.0"},{"time":"2019-08-31","no":"31","value":"0.0"}]}

3
  • 1
    read about function json_decode Commented Aug 5, 2019 at 7:32
  • seems like you got a data in json format so you need to use json_decode (); Commented Aug 5, 2019 at 7:36
  • Possible duplicate of JSON to PHP Array using file_get_contents Commented Aug 5, 2019 at 8:15

1 Answer 1

2

Try this

<?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);
}

?>

You need to grab the URL with 'file_get_contents' and than you need to decode it with json_decode

and then you print it out with the for each function

Sign up to request clarification or add additional context in comments.

1 Comment

Thx works but $data = json_decode($json,true); --> $data = json_decode($json_url,true); ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.