先對需要處理的陣列的鍵值分別做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>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介紹了PHP中json_encode中文被Unicode編碼的解決方法,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。