Javascript-json_encode output

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.