"convert object of class stdclass to json object" Code Answer


$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).

By Levente on February 26 2022

Answers related to “convert object of class stdclass to json object”

Only authorized users can answer the Search term. Please sign in first, or register a free account.