php 如何把中文写入json中 当json文件中还显示的是中文

/***

     * 更新版本

     */

    function showupversionsub(){

        

        #接受post 过来的数据

        $app_type=$_POST['aap_type'];

        if($app_type=='android'||$app_type=='ios'||$app_type=='windows'){

            #组成数组

            $arr=array(

            mainVer=>$_POST['mainVer']==null? '':$_POST['mainVer'],

            upVer=>$_POST['upVer']==null? '':$_POST['upVer'],

            upTips=>$_POST['upTips']==null? '':$_POST['upTips'],

            assetPath=>$_POST['assetPath']==null? '':$_POST['assetPath'],

            newUpiniPath=>$_POST['newUpiniPath']==null? '':$_POST['newUpiniPath'],

            appStore=>$_POST['appStore']==null? '':$_POST['appStore'],

            forceUpdateVersion=>$_POST['forceUpdateVersion']==null? '' :$_POST['forceUpdateVersion']    

            );

            #转化成JSON字符串(兼容中文)

            $str = json_encode($arr);

            $search = "#\\\u([0-9a-f]{1,4}+)#ie";

            $replace = "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))";

            $text=preg_replace($search, $replace, $str);

            #文件路径

            $url="D:/WWW/gm_lequ/gm_lequ/".$app_type.'/update.ini';

            #判断文件的路径是否存在 判断目录是否存在我们用is_dir就OK了。

            if(file_exists($url)){

                $fp=fopen($url, "w+");

                #文件加锁防止多个人同时写入文件

                if(flock($fp, LOCK_EX)){

                    #写入内容

                    fwrite($fp, $text);

                    #文件解锁

                    flock($fp, LOCK_UN);

                    $this->PromptMsg = "更新成功!";

                }else{

                    $this->PromptMsg = "正在写入文件中...请稍等!";

                }

            }else{

                $this->PromptMsg = "文件路径不存在";

            }

        }

        

        $this->UrlJump = "index.php?module=operation&action=upversion&menuId=166";

        $this->promptMsg ();

        

    }

 

你可能感兴趣的:(json)