A sample usage of PHP JSON-related functions

Source: Internet
Author: User
Tags php json
This article mainly introduces the PHP JSON correlation function usage, enumerates the functions of Json_encode, Json_decode and Json_last_error, and analyzes the specific use techniques of json_encode and Json_decode functions, A friend you need can refer to the following

The examples in this article describe the use of PHP JSON-related functions. Share to everyone for your reference, as follows:

List of functions:

function description
json_encode JSON encoding of variables
json_decode
Json_last_error Returns the last error that occurred


For example 1:
Json_encode

$arr =array ("a" = "a", "B" = "B", "C" = "C", "D" and "D"); Echo Json_encode ($arr);

Output

{"A": "A", "B": "B", "C": "C", "D": "D"}

For Example 2: Json_decode

$arr = ' {"A": "A", "B": "B", "C": "C", "D": "D"} '; Var_dump (Json_decode ($arr)); Var_dump (Json_decode ($arr, true));

Output

Object (StdClass) [1] public ' a ' = + string ' A ' (length=1) public ' B ' = = String ' B ' (length=1) public ' C ' = = string ' C ' (length=1) public ' d ' + ' = String ' d ' (length=1) array (size=4) ' a ' + = String ' A ' (length=1) ' B ' = + string ' B ' ( length=1) ' C ' + = String ' C ' (length=1) ' d ' + = String ' d ' (length=1)
Related Article

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.