php - Get JSON object from URL -


i having problems in getting consumption data following json object:

{"version":"0.3","data":{"uuid":"010f5190-83a4-11e4-98cd-d9350366ee4b","from":1423262668135,"to":1454790652371,"min":[1454790652371,27.11945025092],"max":[1454790652371,27.11945025092],"average":27.119,"consumption":237506,"rows":362,"tuples":[[1454790652371,27.119,41140]]}} 

i echo consumption data "237506" not results.

<?php  $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 echo $result->version works without problems...

just tidied json , realised consumption within data key.

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

this why can't access it. try $result->data first data object/array


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -