php - Why doesn't json_decode work with this particular json object? -


so have php script receive json object http://www.reddit.com/search.json via http request , through previous testing, json object. however, when use json_decode on object, error:

catchable fatal error: object of class stdclass not converted string in /home/hudson/ug/xbvg52/public_html/stupid.php on line 5

here (very simple) code:

$query = $_get["radio"]; $url = "https://www.reddit.com/search.json?q=".$query; $response = file_get_contents($url); echo json_decode($response); 

how can convert json object string?

you can't echo json_decode because function makes array of objects, or simple object. try running var_dump(json_decode($response)); , see yourself.

you're getting error because echo expects string , you're sending object.

you transform array string in order echo it.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -