Json data input in PHP

Source: Internet
Author: User
I first use SQL to query the data in the database for json data input in PHP, then traverse the data, and finally use json_encode to output the data. The result output is not of the json type. could you please kindly advise, I am very grateful for the solution!


Reply to discussion (solution)

That is the json data, which is not of the json type.

The result you output is of the json type, but it is a bit problematic if you look at it like this. you just need to go to Baidu online json formatting and put your data in it for formatting, however, this data does not affect your query results, but is only a json display problem.

The result looks like json, but I use ajax for parsing in js. The result is as follows:
1. I write datatype as json in ajax, and no result can be obtained.


2. I comment out datatype and output data to get a string.



So I cannot understand it here.


Where did this come from? Is it json?

Put

The result looks like json, but I use ajax for parsing in js. The result is as follows:
1. I write datatype as json in ajax, and no result can be obtained.


2. I comment out datatype and output data to get a string.



So I cannot understand it here.



This is because you still have HTML code on this page, so you add this exit in echo $ phptest; exit; to stop the output. remember not to use php to output the HTML code before.

Thank you! the problem has been solved.

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.