Home Ask Login Register

Developers Planet

Your answer is one click away!

alx February 2016

Get JSON object from URL

I am having problems in getting the consumption data from the following json object:


I would like to echo the consumption data "237506" but do not get any results.


$url = 'http://vz.xx.de/middleware.php/data/010f5190-83a4-11e4-98cd-d9350366ee4b.json?from=1+year+ago&group=day&tuples=1';
$string = file_get_contents($url, true);
$result = json_decode($string);
echo $result->consumption;


If I echo $result->version it works without problems...


Dan Hanly February 2016

Just tidied the JSON and realised that consumption is within the data key.

    "version": "0.3",
    "data": {
        "consumption": 237506,

This is why you can't access it. Try $result->data first then get your data from this object/array

Post Status

Asked in February 2016
Viewed 2,565 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life