PHP json_encode() 和 json_decode()

<?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";
?>

效果图:

 

猜你喜欢

转载自onestopweb.iteye.com/blog/2380018