sarsar
sarsar

Reputation: 1561

null on json data

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: 165

Answers (3)

NikiC
NikiC

Reputation: 101906

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

deceze
deceze

Reputation: 522005

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

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76870

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

Related Questions