如何在PHP中讓json_encode不轉(zhuǎn)義中文-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!

創(chuàng)新互聯(lián)建站"三網(wǎng)合一"的企業(yè)建站思路。企業(yè)可建設(shè)擁有電腦版、微信版、手機版的企業(yè)網(wǎng)站。實現(xiàn)跨屏營銷,產(chǎn)品發(fā)布一步更新,電腦網(wǎng)絡(luò)+移動網(wǎng)絡(luò)一網(wǎng)打盡,滿足企業(yè)的營銷需求!創(chuàng)新互聯(lián)建站具備承接各種類型的成都做網(wǎng)站、成都網(wǎng)站制作項目的能力。經(jīng)過十年的努力的開拓,為不同行業(yè)的企事業(yè)單位提供了優(yōu)質(zhì)的服務(wù),并獲得了客戶的一致好評。

今天就跟大家聊聊有關(guān)如何在PHP中讓json_encode不轉(zhuǎn)義中文,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

PHP如何讓json_encode不轉(zhuǎn)義中文?

PHP讓json_encode不轉(zhuǎn)義中文的方法:在使用“json_encode()”函數(shù)進行JSON編碼時,在第2個參數(shù)傳入常量“JSON_UNESCAPED_UNICODE”,其意義是以字面編碼多字節(jié)Unicode字符。

代碼示例

$jsonStr = json_encode($data,JSON_UNESCAPED_UNICODE);

JSON 預(yù)定義常量

JSON_ERROR_NONE (integer)

沒有錯誤發(fā)生。自 PHP 5.3.0 起生效。

JSON_ERROR_DEPTH (integer)

到達了大堆棧深度。自 PHP 5.3.0 起生效。

JSON_ERROR_STATE_MISMATCH (integer)

出現(xiàn)了下溢(underflow)或者模式不匹配。自 PHP 5.3.0 起生效。

JSON_ERROR_CTRL_CHAR (integer)

控制字符錯誤,可能是編碼不對。自 PHP 5.3.0 起生效。

JSON_ERROR_SYNTAX (integer)

語法錯誤。 自 PHP 5.3.0 起生效。

JSON_ERROR_UTF8 (integer)

異常的 UTF-8 字符,也許是因為不正確的編碼。 自 PHP 5.3.3 起生效。

JSON_ERROR_RECURSION (integer)

The object or array passed to json_encode() include recursive references and cannot be encoded. If the JSON_PARTIAL_OUTPUT_ON_ERROR option was given, NULL will be encoded in the place of the recursive reference. Available since PHP 5.5.0.

JSON_ERROR_INF_OR_NAN (integer)

The value passed to json_encode() includes either NAN or INF. If the JSON_PARTIAL_OUTPUT_ON_ERROR option was given, 0 will be encoded in the place of these special numbers. Available since PHP 5.5.0.

JSON_ERROR_UNSUPPORTED_TYPE (integer)

A value of an unsupported type was given to json_encode(), such as a resource. If the JSON_PARTIAL_OUTPUT_ON_ERROR option was given, NULL will be encoded in the place of the unsupported value. Available since PHP 5.5.0.

JSON_ERROR_INVALID_PROPERTY_NAME (integer)

A key starting with \u0000 character was in the string passed to json_decode() when decoding a JSON object into a PHP object. Available since PHP 7.0.0.

JSON_ERROR_UTF16 (integer)

Single unpaired UTF-16 surrogate in unicode escape contained in the JSON string passed to json_encode(). Available since PHP 7.0.0.

下面的常量可以和 json_decode() 的 form 選項結(jié)合使用。

JSON_BIGINT_AS_STRING (integer)

將大數(shù)字編碼成原始字符原來的值。 自 PHP 5.4.0 起生效。

JSON_OBJECT_AS_ARRAY (integer)

Decodes JSON objects as PHP array. This option can be added automatically by calling json_decode() with the second parameter equal to TRUE. Available since PHP 5.4.0.

下面的常量可以和 json_encode() 的 form 選項結(jié)合使用。

JSON_HEX_TAG (integer)

所有的 < 和 > 轉(zhuǎn)換成 \u003C 和 \u003E。 自 PHP 5.3.0 起生效。

JSON_HEX_AMP (integer)

所有的 & 轉(zhuǎn)換成 \u0026。 自 PHP 5.3.0 起生效。

JSON_HEX_APOS (integer)

所有的 ' 轉(zhuǎn)換成 \u0027。 自 PHP 5.3.0 起生效。

JSON_HEX_QUOT (integer)

所有的 " 轉(zhuǎn)換成 \u0022。 自 PHP 5.3.0 起生效。

JSON_FORCE_OBJECT (integer)

使一個非關(guān)聯(lián)數(shù)組輸出一個類(Object)而非數(shù)組。 在數(shù)組為空而接受者需要一個類(Object)的時候尤其有用。 自 PHP 5.3.0 起生效。

JSON_NUMERIC_CHECK (integer)

將所有數(shù)字字符串編碼成數(shù)字(numbers)。 自 PHP 5.3.3 起生效。

JSON_PRETTY_PRINT (integer)

用空白字符格式化返回的數(shù)據(jù)。 自 PHP 5.4.0 起生效。

JSON_UNESCAPED_SLASHES (integer)

不要編碼 /。 自 PHP 5.4.0 起生效。

JSON_UNESCAPED_UNICODE (integer)

以字面編碼多字節(jié) Unicode 字符(默認是編碼成 \uXXXX)。 自 PHP 5.4.0 起生效。

JSON_PARTIAL_OUTPUT_ON_ERROR (integer)

Substitute some unencodable values instead of failing. Available since PHP 5.5.0.

JSON_PRESERVE_ZERO_FRACTION (integer)

Ensures that float values are always encoded as a float value. Available since PHP 5.6.6.

JSON_UNESCAPED_LINE_TERMINATORS (integer)

The line terminators are kept unescaped when JSON_UNESCAPED_UNICODE is supplied. It uses the same behaviour as it was before PHP 7.1 without this constant. Available since PHP 7.1.0.

看完上述內(nèi)容,你們對如何在PHP中讓json_encode不轉(zhuǎn)義中文有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝大家的支持。

網(wǎng)站題目:如何在PHP中讓json_encode不轉(zhuǎn)義中文-創(chuàng)新互聯(lián)
文章起源:http://muchs.cn/article36/djhisg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、企業(yè)建站、搜索引擎優(yōu)化、靜態(tài)網(wǎng)站、域名注冊定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化