Convert Object of class stdClass to JSON Object Convert Object of class stdClass to JSON Object json json

Convert Object of class stdClass to JSON Object


$data = json_encode((array)$session); is the right way to go.

I'm guessing that the html you are showing there is what you see in firebug/chrome dev tools/IE dev tools. That is what it looks like after the browser attempts to render it. Try looking at the raw source to see what the output actually looks like. Your problem at this point is caused by the double quotes from json_encode causing the browser engine to consider the onclick attribute closed before the end of the values from $data.

You will need to do some mix of escaping double-quotes and/or using single-quotes in the HTML. I'd start with single-quotes, as that will be more simple. But you will also have to make sure none of the values in $data include unescaped single quotes (as that would result in the same problem).