1

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);
asked Jul 5, 2011 at 8:11
3
  • 2
    Have you tried echoing the contents of $source before you json_decode() it all? Commented Jul 5, 2011 at 8:12
  • 2
    what do you get when you call the url directly before decoding ? Commented Jul 5, 2011 at 8:13
  • The URL returns onSVJson([]) for me, so no wonder Commented Jul 5, 2011 at 8:15

3 Answers 3

4

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.

answered Jul 5, 2011 at 8:22
Sign up to request clarification or add additional context in comments.

Comments

0

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

answered Jul 5, 2011 at 8:14

Comments

0

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.

answered Jul 5, 2011 at 8:25

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.