jeet_0077 Posted February 15, 2008 Share Posted February 15, 2008 Hi I am trying to read the contents of the following link: $link = 'http://sports-ak.espn.go.com/broadband/espn360/upcomingEvents'; $content = file_get_contents($link); $res = json_decode($content, true); the link is returning json out put. But when I use json_decode function its not returning anything. Can you please tell me what went wrong. Or can you please suggest me what has to be done for that. Thanks Link to comment https://forums.phpfreaks.com/topic/91252-can-some-one-help-me-on-this/ Share on other sites More sharing options...
cooldude832 Posted February 15, 2008 Share Posted February 15, 2008 first off is the json library loaded in your php server secondly what specifically is happening because the function doesn't return anything in terms of output it runs a decode on that variable. Link to comment https://forums.phpfreaks.com/topic/91252-can-some-one-help-me-on-this/#findComment-467692 Share on other sites More sharing options...
jeet_0077 Posted February 15, 2008 Author Share Posted February 15, 2008 Thanks for the reply.. Yes I have json installed on the server. I just got the contents using file_get_contents(). Upto this it works fine. Next I have to get the json return value in an array so that I have all the values. I used something like: $var = json_decode($contents, true); tried to do print_r($var); but showing nothing. But is should return the array. In subsequent steps when I try to use any index saying that undefined array index. Link to comment https://forums.phpfreaks.com/topic/91252-can-some-one-help-me-on-this/#findComment-467737 Share on other sites More sharing options...
cooldude832 Posted February 15, 2008 Share Posted February 15, 2008 and your error reporting is where? $var is defined assuming jscon is working properly so print_r($var) should at least return an empty array as you stated Thus this means yuor issue is in jscon Link to comment https://forums.phpfreaks.com/topic/91252-can-some-one-help-me-on-this/#findComment-467741 Share on other sites More sharing options...
rhodesa Posted February 15, 2008 Share Posted February 15, 2008 There are 2 issues: 1) You need to remove the "Events =" off the front of the data 2) There are some special chars in there that the json_decode function does like, specifically: ñ This worked for me: <?php $link = 'http://sports-ak.espn.go.com/broadband/espn360/upcomingEvents'; $content = file_get_contents($link); $content = substr($content,strpos($content,'{')); $content = utf8_encode($content); $res = json_decode($content,true); var_export($res); ?> Link to comment https://forums.phpfreaks.com/topic/91252-can-some-one-help-me-on-this/#findComment-467758 Share on other sites More sharing options...
jeet_0077 Posted February 15, 2008 Author Share Posted February 15, 2008 rhodesa, Thanks it worked for me. Link to comment https://forums.phpfreaks.com/topic/91252-can-some-one-help-me-on-this/#findComment-467867 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.