How to implement json encoding conversion in php

墨辰丷
Release: 2023-03-30 15:56:01
Original
1873 people have browsed it

This article mainly introduces the method of JSON encoding conversion in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.

The details are as follows:

<?php
/*
 * json
 */
$books = array(&#39;key1&#39;=>&#39;value1&#39;,&#39;key2&#39;=>&#39;value2&#39;,&#39;key3&#39;=>array(&#39;key4&#39;=>&#39;value4&#39;,&#39;key5&#39;=>&#39;value5&#39;));
$json = json_encode($books);
$rejson = json_decode($json,true);
echo &#39;原数组:<br/>&#39;;
print_r($books);
echo &#39;<br/><br/>&#39;;
echo &#39;经json编码后:<br/>&#39;;
print $json."<br/>";
echo &#39;<br/>&#39;;
echo &#39;经json解码后:<br/>&#39;;
print_r($rejson);
echo &#39;<br/><br/>&#39;;
//实例
$jsonn = &#39;{"error_code":"400","request":"\/Router\/aQConnectError","api_code":40006,"error":"\u4f20\u5165\u7684\u63a5\u53e3\u53c2\u6570\u51fa\u9519\uff0c\u53c2\u6570openid\u672a\u8bbe\u5b9a\u3002"}&#39;;
print_r(json_decode($jsonn));
?>
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP uses Socket to obtain the SSL certificate and public key of the website

PHP Detailed explanation of the method of downloading remote pictures and saving them locally

Detailed explanation of PHP operation SQLite database classes and usage

The above is the detailed content of How to implement json encoding conversion in php. 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!