Php json data operation_php tutorial

Source: Internet
Author: User
Talk about JSON data operations in PHP. Introduction to JSON data operations in PHP knowledge points in this article: 1. Introduction to JSON data format; 2. data is encoded into JSON format; 3. JSON data is decoded and operated, if necessary, you can talk about JSON data operations in PHP.

Knowledge points in this article: 1. Introduction to JSON data format; 2. data is encoded in JSON format; 3. JSON data is decoded and operated. For more information, see.

JSON, the full name is JavaScript Object Notation. It is a lightweight data exchange format based on the JavaScript programming language ECMA-262 3rd Edition-December 1999 standard, mainly used to exchange data with the server. Similar to XML, it is an independent language and has great advantages in cross-platform data transmission.

Create a json. php file and perform the encode operation first:

?

1

2

3

4

// Encode

// Generate data in JSON format

$ Arr = array (1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello', 'php ');

Echo json_encode ($ arr); // json_encode: converts an object to json format data.

The result is [1, 2, 3, 4, 5, 6, 7, 8, 9, "Hello", "PHP"].

Then perform the decode operation:

?

1

2

3

4

// Decode

$ JsonStr = '{"h": "Hello", "w": "World", "0": [3, 2, 1]}';

$ Obj = json_decode ($ jsonStr );

Echo $ obj-> h; // you can obtain the result by accessing a member.

After knowing how to use it, you can try to capture API data, such as the weather...

The above is all the content of this article. I hope you will like it.

Tips in this article: 1. Introduction to JSON data format; 2. data is encoded in JSON format; 3. JSON data is decoded and operated. if you need it, you can...

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.