An array of PHP backgrounds
After Json_encode output to the foreground, at this time the front desk JS with typeof judge should be JSON object type is it?
Why is it that the string type is displayed
============== Update under =====================
The morning has been figured out, read everyone's answer ~ a lot of points are right
1, Json_encode output is the string,
Whether you are exit (XXX) or echo XXX output to the foreground.
All need to parse a string into an object with Json.parse
2, the output before the head declaration, header (' Content-type:application/json '); The direct output is object.
Reply content:
An array of PHP backgrounds
After Json_encode output to the foreground, at this time the front desk JS with typeof judge should be JSON object type is it?
Why is it that the string type is displayed
============== Update under =====================
The morning has been figured out, read everyone's answer ~ a lot of points are right
1, Json_encode output is the string,
Whether you are exit (XXX) or echo XXX output to the foreground.
All need to parse a string into an object with Json.parse
2, the output before the head declaration, header (' Content-type:application/json '); The direct output is object.
If you write like that, you're the object.
If you have a quotation mark, it is a string.
In particular, please ask the Lord Code bar ~
PHP json_encode Output is a string, you can use JavaScript Json_parse parse the string as a JavaScript object
Background output is a stream, here lost all the type related, in fact, the browser is also a stream, and then JS Engine converted to the basic type, JS is a weak type, and then JSON does not seem to be judged by TypeOf, JSON is just a format, a specification
Head declaration JSON, try it.
Header (' Content-type:application/json ');
If you look at the output of Json_encode, you know why typeof is a string.