Usage examples of phpjson functions

Source: Internet
Author: User
Tags php json
This article mainly introduces the usage of phpjson-related functions, lists the functions of json_encode, json_decode, and json_last_error, and analyzes the specific usage skills of json_encode and json_decode functions, for more information about the usage of json-related php functions, see this article. the functions of json_encode, json_decode, and json_last_error are listed. the usage skills of json_encode and json_decode functions are analyzed, for more information, see

This example describes the usage of php json-related functions. We will share this with you for your reference. The details are as follows:

Function list:

Function Description
Json_encode Encode variables in json format
Json_decode Decodes json strings and converts them to php variables.
Json_last_error Returns the last error.


For example 1:
Json_encode

$arr=array("A"=>"a","B"=>"b","C"=>"c","D"=>"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)

The above is a detailed explanation of the usage examples of php json-related functions. For more information, see other related articles in the first PHP community!

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.