php - json_decode returns NULL for a json data retrieved from an api -


i retreiving json data cloudmade api using php, , using json_decode parse it. returns null. ideas why happening helpful. code shown below:

$url = 'http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'.$curr_x.','.$curr_y.','.$dest_x.','.$dest_y.'/car.js';     $acontext = array(         'http' => array(             'proxy' => 'tcp://10.3.100.212:8080',             'request_fulluri' => true,             'header' => 'accept-charset: utf-8, *;q=0'         ),     );     $cxcontext = stream_context_create($acontext);      $sfile = file_get_contents($url, false, $cxcontext);     //echo $sfile;     $obj = json_decode($sfile);     print $obj;     print $obj->{'total_time'}; 

below sample json data retrieving:

{"version":0.3,"status":0,"route_summary":{"total_distance":280574,"total_time":11505,"start_point":"hwy2","end_point":"hwy14"},"route_geometry":[[25.28581,121.602463],[25.28508,121.603691],[25.28401,121.604752],[25.28265,121.605553],[25.28133,121.6064],[25.281059,121.606613],[25.280451,121.607819],[25.280149,121.608543],[25.27976,121.610397],[25.279289,121.611794],[25.279119,121.61248],[25.2791,121.613541],[25.278839,121.614532],[25.278351,121.615669],[25.2777,121.616783],[25.27721,121.617447],[25.27286,121.622032],[25.26898,121.62632],[25.2658,121.628899],[25.263941,121.63031],[25.26215,121.631302],[25.259251,121.632896],[25.258341,121.63324],[25.25765,121.63327],[25.257299,121.633324],[24.005039,121.059502]],"route_instructions": [["head southeast on hwy2",479,0,23,"0.5 km","se",123.2],["continue on hwy2",205,3,10,"0.2 km","se",149.6,"c",357.8],["slight left @ hwy2",12918,5,620,"12.9 km","se",119.3,"tsll",335.3],["continue on hwy2",1248,96,60,"1.2 km","e",107.9,"c",359.9],["continue on hwy2",4221,109,203,"4.2 km","e",86.6,"c",0.0],["continue",221,145,11,"0.2 km","s",164.6,"c",12.8],["slight right",749,150,36,"0.7 km","se",151.9,"tslr",9.3],["slight left",5755,160,276,"5.8 km","s",186.8,"tsll",333.1],["slight left @ hwy2",1840,269,88,"1.8 km","se",124.5,"tsll",326.7],["turn right @ fwy3\/ç¦��ç��¾æ��©æ²�é«��é�顫å��¬è·¯ (formosa freeway)",2601,305,117,"2.6 km","s",159.0,"tr",68.6],["continue on fwy3\/ç¦��ç��¾æ��©æ²�é«��é�顫å��¬è·¯ (formosa freeway)",8484,328,339,"8.5 km","s",196.8,"c",355.8],["slight right",2454,404,110,"2.5 km","sw",206.6,"tslr",9.0],["slight right @ fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",8802,428,352,"8.8 km","w",266.5,"tslr",8.2],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",16984,455,679,"17.0 km","w",290.9,"c",0.5],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",2129,556,85,"2.1 km","w",251.5,"c",0.0],["slight left @ fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",6560,567,262,"6.6 km","w",258.6,"tsll",354.7],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",651,636,26,"0.7 km","w",261.6,"c",0.2],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",8269,639,331,"8.3 km","w",267.7,"c",1.9],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",2914,691,117,"2.9 km","sw",239.6,"c",0.0],["slight left @ fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",8227,699,329,"8.2 km","sw",225.0,"tsll",358.2],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",6311,706,252,"6.3 km","sw",222.4,"c",0.8],["slight left @ fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",2433,722,97,"2.4 km","sw",219.7,"tsll",353.9],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",3964,736,159,"4.0 km","sw",205.2,"c",0.1],["slight left @ fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",27836,751,1113,"27.8 km","sw",224.0,"tsll",354.4],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",3188,830,128,"3.2 km","sw",210.0,"c",3.8],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",5626,839,225,"5.6 km","s",188.3,"c",359.8],["slight left @ fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",729,864,29,"0.7 km","sw",244.9,"tsll",353.4],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",20400,870,816,"20.4 km","sw",213.2,"c",0.2],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",57912,948,2316,"57.9 km","sw",206.9,"c",355.8],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",5941,1409,238,"5.9 km","s",186.9,"c",0.3],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",4580,1439,183,"4.6 km","sw",243.5,"c",359.1],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",4743,1461,190,"4.7 km","sw",206.7,"c",2.7],["continue on fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",7445,1482,298,"7.4 km","s",184.7,"c",358.7],["slight left @ fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",1471,1526,59,"1.5 km","w",289.1,"tsll",355.6],["slight left @ fwy1\/中山é«��é�顫å��¬è·¯ (jhongshan freeway)",3024,1535,121,"3.0 km","w",258.5,"tsll",353.7],["slight right",1157,1551,52,"1.2 km","sw",232.6,"tslr",8.4],["slight right",4609,1570,207,"4.6 km","ne",26.5,"tslr",29.9],["slight left @ fwy3\/ç¦��ç��¾æ��©æ²�é«��é�顫å��¬è·¯ (formosa freeway)",8075,1609,323,"8.1 km","e",102.0,"tsll",358.4],["slight left @ fwy3\/ç¦��ç��¾æ��©æ²�é«��é�顫å��¬è·¯ (formosa freeway)",4611,1680,184,"4.6 km","se",116.5,"tsll",354.5],["continue on fwy3\/ç¦��ç��¾æ��©æ²�é«��é�顫å��¬è·¯ (formosa freeway)",2669,1708,107,"2.7 km","s",160.6,"c",3.9],["slight right",22697,1719,1021,"22.7 km","sw",232.5,"tslr",18.0],["continue on fwy6",14915,1788,597,"14.9 km","e",77.9,"c",9.6],["continue on fwy6",11333,1815,453,"11.3 km","e",73.7,"c",351.8],["turn left @ hwy14",8019,1849,385,"8.0 km","e",86.5,"tl",261.1]]} 

change $sfile $sfile

$url = 'http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'.$curr_x.','.$curr_y.','.$dest_x.','.$dest_y.'/car.js';     $acontext = array(         'http' => array(             'proxy' => 'tcp://10.3.100.212:8080',             'request_fulluri' => true,             'header' => 'accept-charset: utf-8, *;q=0'         ),     );     $cxcontext = stream_context_create($acontext);      $sfile = file_get_contents($url, false, $cxcontext);     //echo $sfile;     $obj = json_decode($sfile);     print $obj;     print $obj->{'total_time'}; 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -