JSON advanced article 1 use JSON in PHP and javascript

Source: Internet
Author: User
I. JSON introduction JSON (JavaScriptObjectNotation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C,... SyntaxHighlighter. 1. JSON introduction
JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C, C ++, C #, Java, JavaScript, Perl, Python, and so on ). These features make JSON an ideal data exchange language. For more information about JSON, visit the JSON official website. we recommend that you study it carefully. In addition, the introduction of JSON in Wikipedia is also very detailed. you can visit it.
 
II. JSON encoding in PHP
It is very easy to generate a JSON string in PHP. you can directly use the json_encode () function to convert PHP data into a JSON string. The original form of this function is as follows:
 
String json_encode (mixed $ value)
 
This function can transcode any data except the resource type.
 
III. parse JSON using Javascript
There are two methods: one is to directly use the eval () function. This method is the fastest. However, because the eval method can execute arbitrary JavaScript code, security issues may occur when the data source is unreliable. For example, the following example causes Page redirection:
 
[Html] view plaincopy
 
 
 
A section of JSON data that causes Page redirection using eval () interpretation 

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.