Reputation: 1561
I am trying to parse this json data from the url but i get NULL how do i fix this issue.
$source = file_get_contents('http://partners.socialvi.be/e414f702cf3db89a2fe58066bbab369d65b6a058/activities/available.json');
$json = json_decode($source);
var_dump($json);
Upvotes: 1
Views: 166
Reputation: 101956
Remove the last part of the URL (&callback=onSVJson
) and it'll work.
Many APIs offer a feature called JSONP, that allows the JSON to be passed to a callback function, in order to simplify access via cross domain JavaScript. But for PHP you don't need that.
The name of the callback function is typically specified using the callback
GET parameter. If you leave that out, no callback function is used - just plain JSON.
Upvotes: 0
Reputation: 522625
That's because the API returns the data in JSONP format, not pure JSON. Notice the surrounding onSVJson([])
. You'll either have to strip this out, or read the API documentation and try another request format. My guess would be that leaving out the final &callback=onSVJson
should do the trick.
Upvotes: 4
Reputation: 76910
That's because if you call the url (go to http://partners.socialvi.be/e414f702cf3db89a2fe58066bbab369d65b6a058/activities/available.json?network_user_id=3459874&max_activities=9&callback=onSVJson with your browser) the json that is returned has no values
Upvotes: 0