Detailed explanation of the usage of php json related functions

墨辰丷
Release: 2023-03-27 19:24:01
Original
1535 people have browsed it

This article mainly introduces the usage of php json 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 with examples. Friends in need can refer to it

The examples in this article describe the usage of php json related functions. Share it with everyone for your reference, the details are as follows:

Function list:


Function Description
json_encode Json encoding of variables
json_decode Decode the string in json format and convert it into a php variable
json_last_error Return the last error that occurred


##For example 1: json_encode

$arr=array("A"=>"a","B"=>"b","C"=>"c","D"=>"d");
echo json_encode($arr);
Copy after login

output:

{"A":"a","B":"b","C":"c","D":"d"}
Copy after login

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));
Copy after login

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)
Copy after login

The above is the entire content of this article, I hope it will help everyone learn Helps.


Related recommendations:

A brief analysis of the difference between json and jsonp and obtaining it through ajax jsonPost-data format conversion

Convert form elements to JSON by constructing AJAX parameters

SpringMVC Ajax asynchronous request for JSON format data implemented in the environment

The above is the detailed content of Detailed explanation of the usage of php json related functions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!