---
title: "PHP json_encode() 和 json_decode()"
author: "onestopweb"
date: "2017-06-18T10:25:31Z"
tags: []
categories: ["编程语言"]
slug: "php-json-encode-json-decode"
draft: false
lastmod: "2017-06-18T10:25:45Z"
id: 2380018
url: "https://onestopweb.iteye.com/blog/2380018"
---

```
<?php
header('Content-Type: text/html; charset=utf-8');
$json = '{"a":"一","b":"二","c":"三","d":"四","e":"五"}'; 

$j1 = json_encode($json);
$j2 = json_encode($json, JSON_HEX_TAG);
$j3 = json_encode($json, JSON_HEX_APOS);
$j4 = json_encode($json, JSON_HEX_QUOT);
$j5 = json_encode($json, JSON_HEX_AMP);

echo "Normal 编码: ", $j1, "\n"; 
echo "Tags 编码: ", $j2, "\n"; 
echo "Apos 编码: ", $j3, "\n"; 
echo "Quot 编码: ", $j4, "\n"; 
echo "Amp 编码: ", $j5, "\n\n";

echo "Normal 解码: ", json_decode($j1), "\n"; 
echo "Tags 解码: ", json_decode($j2), "\n"; 
echo "Apos 解码: ", json_decode($j3), "\n"; 
echo "Quot 解码: ", json_decode($j4), "\n"; 
echo "Amp 解码: ", json_decode($j5), "\n\n";
?>
```

 

效果图：  
![](http://dl2.iteye.com/upload/attachment/0125/5632/34343265-ca4f-3deb-8459-56a7418b8768.png)