Decoding JSON feed via PHP from Twitter not working?

decode, json, php, twitter

Solution

With `callback` in the URL, you get a string back that is wrapped in parenthesis `(` `)` (excerpt of the string):

([{"in_reply_to_user_id":  /* ...more data here...*/ }]);

This is not valid JSON.

Without `callback`, the result is only wrapped in `[` `]` which is valid:

 [{"in_reply_to_user_id":  /* ...more data here...*/ }]

Problem

So I'm pulling down a user's tweet steam in JSON format via PHP. I'd like to decode it into an associative array or at least some more usable fashion rather than a string so that I can maneuver through it. I've been reading like mad about json_decode, but for me it seems like when I use it, before and after, the contents of the file is still being detected as one long string. Can anyone help me figure out what I am doing wrong? ``` $url = "http://twitter.com/status/user_timeline/" . $username . ".json?count=" . $count . "&callback=?"; // $url becomes "http://twitter.com/status/user_timeline/steph_Rose.json?count=5&callback=?"; $contents = file_get_contents($url); $results = json_decode($contents, true); echo "<pre>"; print_r($results); echo "</pre>"; echo gettype($results); // this returns string ```

Original source