Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- json_decode() returns string type?
August 24, 2007, 5:35 pm
rate this thread
I'm passing a JSON-encoded string to json_decode() and am expecting
its output to be an object type, but am getting a string type instead.
How can I return an object?
In the docs, the following returns an object:
$json = '';
However, if I json_encode() the string first and then call
json_decode(), the output is a string and not an object:
$json = json_encode('');
This is just a simplified example--in practice what I'm doing is
pushing a JSON-encoded string to PHP via AJAX (or at least "AJ" ;).
However it does illustrate the problem of converting this encoded JSON
string to an object I can read in PHP (e.g., "$json->a").
How can I return an object type?