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

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

新洲ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!

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

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

代碼示例

$jsonStr = json_encode($data,JSON_UNESCAPED_UNICODE);

JSON 預(yù)定義常量

JSON_ERROR_NONE (integer)

沒(méi)有錯(cuò)誤發(fā)生。自 PHP 5.3.0 起生效。

JSON_ERROR_DEPTH (integer)

到達(dá)了最大堆棧深度。自 PHP 5.3.0 起生效。

JSON_ERROR_STATE_MISMATCH (integer)

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

JSON_ERROR_CTRL_CHAR (integer)

控制字符錯(cuò)誤,可能是編碼不對(duì)。自 PHP 5.3.0 起生效。

JSON_ERROR_SYNTAX (integer)

語(yǔ)法錯(cuò)誤。 自 PHP 5.3.0 起生效。

JSON_ERROR_UTF8 (integer)

異常的 UTF-8 字符,也許是因?yàn)椴徽_的編碼。 自 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 選項(xiàng)結(jié)合使用。

JSON_BIGINT_AS_STRING (integer)

將大數(shù)字編碼成原始字符原來(lái)的值。 自 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 選項(xiàng)結(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)

使一個(gè)非關(guān)聯(lián)數(shù)組輸出一個(gè)類(Object)而非數(shù)組。 在數(shù)組為空而接受者需要一個(gè)類(Object)的時(shí)候尤其有用。 自 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 字符(默認(rèn)是編碼成 \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)容,你們對(duì)如何在PHP中讓json_encode不轉(zhuǎn)義中文有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

本文標(biāo)題:如何在PHP中讓json_encode不轉(zhuǎn)義中文
瀏覽地址:http://bm7419.com/article48/jcieep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷推廣、標(biāo)簽優(yōu)化、Google、品牌網(wǎng)站建設(shè)網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站

廣告

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

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