先对需要处理的数组的键值分别做urlencode处理,然后json_encode,最后做urldecode处理 。
<code><span><span>function</span><span>encode_json</span><span>(<span>$str</span>)</span> {</span><span>return</span> urldecode(json_encode(url_encode(<span>$str</span>))); } <span>/** *@desc 递归的处理数组中的每一个键值对 */</span><span><span>function</span><span>url_encode</span><span>(<span>$str</span>)</span> {</span><span>if</span>(is_array(<span>$str</span>)) { <span>foreach</span>(<span>$str</span><span>as</span><span>$key</span>=><span>$value</span>) { <span>$str</span>[urlencode(<span>$key</span>)] = url_encode(<span>$value</span>); } } <span>else</span> { <span>$str</span> = urlencode(<span>$str</span>); } <span>return</span><span>$str</span>; } </code>
以上就介绍了PHP中json_encode中文被Unicode编码的解决办法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。