$array = array("name" => "Eric","age" => 23);
echo json_encode($array);
代码如下 |
复制代码 |
$array = array(0 => "Eric", 1 => 23);
echo json_encode($array);
|
The program will print out:
{“name”:”Eric”,”age”:23}
代码如下 |
复制代码 |
$json = ’{"name":"zhangsan","age":20,"sex":"nan"}’;
print_r(json_decode($json,true));
|
Look at the following example:
The code is as follows
|
Copy code
|
$array = array(0 => "Eric", 1 => 23);
echo json_encode($array);
|
The program will print out:
["Eric",23]
In this way, json can be converted into array form, and the key remains in the original format
The code is as follows
|
Copy code
|
$json = ’{"name":"zhangsan","age":20,"sex":"nan"}’;
print_r(json_decode($json,true));
After parsing such json data, it will become an array like the following
Array
[name] => zhangsan
[age] => 20
[sex] => nan
)
http://www.bkjia.com/PHPjc/628751.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628751.htmlTechArticleConverting arrays to json in PHP is very simple, we only need to use json_encode() and json_decode(). It is easy to understand that json_encode() converts a PHP array into Json. Instead, json_decode() is...
|
|