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)