溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

php如何把json unicode轉(zhuǎn)中文

發(fā)布時間:2023-01-31 11:34:12 來源:億速云 閱讀:96 作者:iii 欄目:編程語言

本文小編為大家詳細(xì)介紹“php如何把json unicode轉(zhuǎn)中文”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“php如何把json unicode轉(zhuǎn)中文”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識吧。

php把json unicode轉(zhuǎn)中文的方法:1、使用“json_encode($log['result_data'],JSON_UNESCAPED_UNICODE);”方法進(jìn)行轉(zhuǎn)換;2、使用“function unicodeDecode($unicode_str){...}”方法進(jìn)行轉(zhuǎn)換即可。

PHP把unicode編碼的json字符串轉(zhuǎn)中文

json中中文被編碼

$s = '[{"param_name":"email","param_caption":"\u90ae\u7bb1","operator":"\u5305\u542b","value":"aaaa\u5927\u592b\u6492"}]';

將中文編碼轉(zhuǎn)成中文

方法1.

json_encode($log['result_data'],JSON_UNESCAPED_UNICODE);

方法2.

   /**
     * 把unicode編碼的字符串轉(zhuǎn)為人眼可看的字符串
     * @param $unicode_str
     *
     * @return string
     */
    function unicodeDecode($unicode_str){
        $unicode_str = str_replace('"', '\"', $unicode_str);
        $unicode_str = str_replace("'", "\'", $unicode_str);
        $json = '{"str":"'.$unicode_str.'"}';
 
        $arr = json_decode($json,true);
 
        if(empty($arr)){
            return '';
        }
 
        return $arr['str'];
    }

結(jié)果:

[{"param_name":"email","param_caption":"郵箱","operator":"包含","value":"aaaa大夫撒"}]

讀到這里,這篇“php如何把json unicode轉(zhuǎn)中文”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點(diǎn)還需要大家自己動手實(shí)踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI