Javascript-json Data Format

Source: Internet
Author: User
On the server side, I use PHP to write a json file in the format {}{}{}, file_put_contents is used to append the data to the client. js. It is also obtained through PHP in the format of {}{} (file_get_contents), rather than the standard json format [{},{}, {}] How can I get standard js... on the server side, I used PHP to write a json file in the format of {}{}{}. I used file_put_contents to write additional files.

The format {} (file_get_contents) obtained through PHP in client js is not the standard json format [{}, {}, {}]

How can I get the standard json format? When writing data in PHP (PHP only obtains {key/value}. How can this problem be solved ?), Or after js obtains the string, convert it to the standard format (how to do it ?)?

Ask a newbie, thanks.

Reply content:

On the server side, I used PHP to write a json file in the format of {}{}{}. I used file_put_contents to write additional files.

The format {} (file_get_contents) obtained through PHP in client js is not the standard json format [{}, {}, {}]

How can I get the standard json format? When writing data in PHP (PHP only obtains {key/value}. How can this problem be solved ?), Or after js obtains the string, convert it to the standard format (how to do it ?)?

Ask a newbie, thanks.

Put the content you want to write in$data = array();Medium,
Use

$data[] = $xxxxx;$data[] = $yyyyy;//....file_put_contents('xx.js', json_encode($data));

ThenjsYou can load thisxx.jsNow.

It is recommended that the backend server write files in the standard JSON format, and the front-end can directly parse the files.

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.