I have a stdClass
object called $post
that, when dumped via print_r()
, returns the following:
stdClass Object (
[ID] => 12981
[post_title] => Alumnus' Dinner Coming Soon
[post_parent] => 0
[post_date] => 2012-01-31 12:00:51
)
Echoing the result from calling json_encode()
on this object results in the following:
{
"ID": "12981",
"post_title": null,
"post_parent": "0",
"post_date": "2012-01-31 12:00:51"
}
I'm assuming that something with the single quote is causing json_encode
to choke, but I don't know what format is needed to escape that. Any ideas?
EDIT: Fixed mismatch in code examples. I'm running PHP version 5.3.8
EDIT2: Directly after encoding the object, I did this:
echo json_last_error() == JSON_ERROR_UTF8;
This printed 1
, which means that the following error occurred: "Malformed UTF-8 characters, possibly incorrectly encoded". json_last_error()
EDIT3: Calling utf8_decode()
on the post title resulted in the following: "Alumnus? Dinner Coming Soon". This data is being pulled from a MySQL database - the post title in particular is a text field, UTF-8 encoded. Maybe this single-quote is improperly encoded? The thing is, I have a SQL GUI app, and it appears correctly in that.