目次
PHP json_encode() 関数の紹介

php json_encode

Aug 08, 2016 am 09:27 AM
array encode json nbsp quot

PHP json_encode() 関数の紹介


php (php > 5.2) の json_encode() 組み込み関数を使用すると、php のデータを他の言語にうまく転送できます。そして使用されました。

この関数の機能は、数値をjsonデータの保存形式に変換することです。

01<tdcourier new border:0px outline:0px float:none vertical-align:top position:static left:auto top:auto right:auto bottom:auto height:auto width:3em line-height:1.1em min-height:inherit color:rgb background:none><tdcourier new rgb><codecourier new important><?php01<?php

02$arr = array

03 (
🎜🎜🎜🎜🎜02🎜$arr = 配列🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜03🎜 (コード>コード>🎜🎜🎜🎜</p><p><table><tbody><tr><tdCourier New',Courier,monospace!important; border:0px!important; outline:0px!important; float:none!important; vertical-align:top!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.1em!important; min-height:inherit!important; color:rgb(175,175,175)!important; background:none!important"><codeCourier New',Courier,monospace!重要; min-height:継承!重要;表示:ブロック!重要;背景:なし!重要">0404 'Name'=>'你妹',

05          'Age'=>22

06       ); 'Name' =>'你妹' ,
🎜🎜🎜🎜🎜🎜05🎜 '年齢'=>22🎜🎜 🎜🎜🎜🎜🎜🎜🎜🎜06🎜 );🎜🎜🎜🎜

0707 

08$jsonencode 08$arr);

09echo $jsonencode;$jsonencode= json_encode(
$arr🎜🎜);🎜🎜🎜🎜 🎜🎜🎜🎜🎜🎜09🎜🎜echo🎜 $jsonencode🎜🎜;🎜🎜🎜🎜🎜

1010?>

程序运行结果如下:

1{"Name":null,"Age":20}

json_encode 函数中中文被编码成 null 了,Google 了一下,很简单,为了与前端紧密结合,Json 只支持 utf-8 编码,我认为是前端的 Javascript 也是 utf-8 的原因。

1<?php?>
🎜🎜🎜🎜程序运行结果如下:🎜🎜🎜 🎜🎜🎜🎜1🎜{"名前":null,"Age":20}🎜🎜🎜🎜🎜🎜🎜🎜json_encode関数数中中文被编码成 null 了,Google 了一下,很简单,為了与前端紧密结合,Json のみ utf- をサポート8 暗号、フロントエンドの Javascript も utf-8 の原因であると考えています。等幅!重要; min-height:継承!重要;表示:ブロック!重要;背景:なし!重要">1🎜<?php🎜🎜🎜🎜

22$array = array

3 ($array = 配列
🎜🎜🎜🎜🎜🎜3🎜 (🎜🎜🎜🎜

44 'name'=>iconv('GB18030','utf-8','你妹'),

5        'sex'=>'men' '名前' =>iconv('GB18030 ', 'utf-8' ,'你妹'),
🎜🎜🎜🎜🎜5🎜 'sex'=>「男性」🎜🎜🎜🎜

66    );

7 

8echo json_encode($array); );
🎜🎜🎜 🎜🎜🎜7🎜8🎜echo json_encode($array);🎜🎜🎜🎜

99?>

这个程序的运行结果为:

1{"title":"u6d63u72b2ue785","body":"men"}?>
🎜🎜🎜🎜この这个程序の実行結果:🎜 🎜🎜🎜🎜🎜🎜1🎜{"タイトル":"u6d63u72b2ue785","body":"男性"}🎜🎜🎜🎜
iconv は形式を変換するときに GBK を使用しますが、GB2312 には 6763 文字しか含まれていないため、iconv はエラーを報告します。収集されていない中国語の文字が表示されると、iconv はエラーを報告します。 GBK は GB2312-80 と完全に下位互換性があり、より多くの文字をサポートしますが、それでもエラーは発生します。GB18030 は基本的に GBK と互換性があり、100 を超えるフォントを拡張します。

配列内のすべての中国語文字が欠落しているか、json_encode の後に u6d63 などが表示されます。

解決策は、urlencode() 関数を使用して以下を処理することです。json_encode の前に、urlencode() を使用してすべての配列の内容を処理し、次に json_encode() を使用してそれを JSON 文字列に変換し、最後に urldecode を使用します。 () で渡した中国語をエンコードします。

01<tdcourier new border:0px outline:0px float:none vertical-align:top position:static left:auto top:auto right:auto bottom:auto height:auto width:3em line-height:1.1em min-height:inherit color:rgb background:none><tdcourier new rgb><codecourier new important><?php01<?php

02/**************************************************************

03 *
🎜🎜🎜🎜🎜02🎜/************** ******************************************🎜🎜🎜🎜 🎜🎜 🎜🎜🎜🎜03🎜 < /code><codeCourier New',Courier,monospace! important; color:rgb(0,130,0)! important">*🎜🎜🎜 🎜

04 *  特定の関数を使用して数グループ内のすべての要素を実行します

05<codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">05 <tdCourier New',Courier,monospace!重要; border-width:0px 0px 0px 3px! important; border-left-style:solid! important; border-left-color:rgb( 108,226,108)!重要; フロート:なし!重要; 左:自動!重要; :auto!重要; 高さ:自動!重要; 行の高さ:1.1em!重要; 背景:なし!重要"><codeCourier,monospace!重要; min-height:継承!重要;背景:なし!重要"> *  @param string &$array 要处理的文字列

06 <codeCourier New',Courier,monospace! important; min-height:継承!重要;表示:ブロック!重要;背景:なし!重要">06 </tr></tbody>*  @param string $function 要実行関数数</table>🎜🎜🎜🎜</p><p><table><tbody><tr><tdCourier New',Courier,monospace!important; border:0px!important; outline:0px!important; float:none!important; vertical-align:top!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.1em!important; min-height:inherit!important; color:rgb(175,175,175)!important; background:none!important"><codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">07 *  @return boolean $apply_to_keys_only 否かもキー上に

08<codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">08 <tdCourier New',Courier,monospace!重要; border-width:0px 0px 0px 3px! important; border-left-style:solid! important; border-left-color:rgb( 108,226,108)!重要; フロート:なし!重要; 左:自動!重要; :auto!重要; 高さ:自動!重要; 行の高さ:1.1em!重要; 背景:なし!重要"><codeCourier New',Courier,monospace!重要; min-height:継承!重要;背景:なし!重要"> *  @access public

09 *09</tr></tbody><tdCourier New',Courier,monospace! important; border-width:0px 0px 0px 3px! important; border-left-style:solid! important; border-left-color:rgb( 108,226,108)!重要; フロート:なし!重要; 左:自動!重要; :auto!重要; 高さ:自動!重要; 行の高さ:1.1em!重要; 背景:なし!重要"><codeCourier New',Courier,monospace!重要; min-height:継承!重要;背景:なし!重要"> </table>🎜*🎜🎜🎜🎜🎜</p><p><table><tbody><tr><tdCourier New',Courier,monospace!important; border:0px!important; outline:0px!important; float:none!important; vertical-align:top!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.1em!important; min-height:inherit!important; color:rgb(175,175,175)!important; background:none!important"><codeCourier New',Courier,monospace!重要; min-height:継承!重要;表示:ブロック!重要;背景:なし!重要">10<codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">10 *************************************************************/

11function arrayRecursive(&$array, $function, $apply_to_keys_also<tdCourier New',Courier,monospace!重要; border-width:0px 0px 0px 3px! important; border-left-style:solid! important; border-left-color:rgb( 108,226,108)!重要; フロート:なし!重要; 左:自動!重要; :auto!重要; 高さ:自動!重要; 幅:自動!重要; min-高さ:継承!重要; ****************************************** ******************/</tr></tbody></table></p><p><table><tbody><codeCourier New',Courier,monospace! important; :block!重要; 背景:なし!重要">11<tr><tdCourier New',Courier,monospace!important; border:0px!important; outline:0px!important; float:none!important; vertical-align:top!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.1em!important; min-height:inherit!important; color:rgb(175,175,175)!important; background:none!important"><tdCourier New',Courier,monospace!重要;ボーダー幅:0px 0px 0px 3px!重要; border-left-style:solid!重要; border-left-color:rgb(108,226,108)!重要;アウトライン:0px!重要; float:none!重要;垂直配置:トップ!重要;位置:静的!重要;左:自動!重要;トップ:自動!重要;右:自動!重要;下:自動!重要;高さ:自動!重要;幅:自動!重要;行の高さ:1.1em!重要; min-height:継承!重要;背景:なし!重要"><codeCourier New',Courier,monospace!重要; font-weight:bold!重要; min-高さ:継承!重要; カラー:rgb(0,102,153)!重要; 背景:なし!重要"> function<codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">12{ arrayRecursive(&$array</tbody></table>, 🎜 <codeCourier New',Courier,monospace! important; min-height:inherit! important; background:none! important">$function🎜🎜, 🎜<codeCourier New',Courier,等幅!重要; 最小高さ:継承!重要; カラー:rgb(170,119,0)!重要; 背景:なし!重要">$apply_to_keys_only false)🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜<codeCourier New',Courier,monospace!重要; min-height:継承!重要;表示:ブロック!重要;背景:なし!重要">12🎜🎜<tdCourier New',Courier,monospace! important; border-width:0px 0px 0px 3px! important; border-left-style:solid! important; border-left-color:rgb( 108,226,108)!重要; フロート:なし!重要; 左:自動!重要; :自動!重要; 高さ:自動!重要; 行の高さ:1.1 重要; 背景:なし!重要;</p><p><table><tbody><tr><tdCourier New',Courier,monospace!important; border:0px!important; outline:0px!important; float:none!important; vertical-align:top!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.1em!important; min-height:inherit!important; color:rgb(175,175,175)!important; background:none!important"><codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">13 static $recursive_counter = 0;

14<codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">14 if (&#43;&#43;$recursive_counter<tdCourier New',Courier,monospace!重要; border-width:0px 0px 0px 3px! important; border-left-style:solid! important; border-left-color:rgb( 108,226,108)!重要; フロート:なし!重要; 左:自動!重要; :auto!重要; 高さ:自動!重要; 行の高さ:1.1em!重要; 背景:なし!重要"> if</tr> </tbody>(++</table><codeCourier New',Courier,monospace!重要; min-height:inherit!重要; カラー:rgb(170,119,0)!重要; 背景:なし!重要" >$recursive_counter🎜 🎜> 1000) {🎜🎜🎜🎜🎜</p><p><table><tbody><tr><tdCourier New',Courier,monospace!important; border:0px!important; outline:0px!important; float:none!important; vertical-align:top!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.1em!important; min-height:inherit!important; color:rgb(175,175,175)!important; background:none!important"><codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">15 die('可能です 深い再帰攻撃');<codeCourier New',Courier,monospace!important; min-height:inherit!important; background:none!important">);

16 }
🎜🎜🎜🎜🎜🎜16🎜🎜<tdCourier New',Courier,monospace!重要;ボーダー幅:0px 0px 0px 3px!重要; border-left-style:solid!重要; border-left-color:rgb(108,226,108)!重要;アウトライン:0px!重要; float:none!重要;垂直配置:トップ!重要;位置:静的!重要;左:自動!重要;トップ:自動!重要;右:自動!重要;下:自動!重要;高さ:自動!重要;幅:自動!重要;行の高さ:1.1em!重要; min-height:継承!重要;背景:なし!重要"><codeCourier New',Courier,monospace!重要; min-height:inherit!重要; 背景:なし!重要"> 🎜<codeCourier New',Courier,monospace!重要; min-height:継承!重要;背景:なし!重要">}🎜🎜🎜🎜🎜</p><p><table><tbody><tr><tdCourier New',Courier,monospace!important; border:0px!important; outline:0px!important; float:none!important; vertical-align:top!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.1em!important; min-height:inherit!important; color:rgb(175,175,175)!important; background:none!important"><codeCourier New',Courier,monospace!important; min-height:inherit!important; display:block!important; background:none!important">17 foreach ($array as $key => $value) {

1818        if (is_array($valueif (is_array
🎜(🎜$value🎜🎜)) {🎜🎜🎜🎜🎜

1919            arrayRecursive($array[$key], $function$apply_to_keys_also);

20 arrayRecursive($array🎜[$key🎜]、$function🎜, $apply_to_keys_も🎜);🎜
🎜🎜🎜🎜🎜🎜20🎜🎜🎜 &nbs
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Windows 11で明るさを調整する10の方法 Windows 11で明るさを調整する10の方法 Dec 18, 2023 pm 02:21 PM

画面の明るさは、最新のコンピューティング デバイスを使用する上で不可欠な部分であり、特に長時間画面を見る場合には重要です。目の疲れを軽減し、可読性を向上させ、コンテンツを簡単かつ効率的に表示するのに役立ちます。ただし、設定によっては、特に新しい UI が変更された Windows 11 では、明るさの管理が難しい場合があります。明るさの調整に問題がある場合は、Windows 11 で明るさを管理するすべての方法を次に示します。 Windows 11で明るさを変更する方法【10の方法を解説】 シングルモニターユーザーは、次の方法でWindows 11の明るさを調整できます。これには、ラップトップだけでなく、単一のモニターを使用するデスクトップ システムも含まれます。はじめましょう。方法 1: アクション センターを使用する アクション センターにアクセスできる

iPhoneのSafariでプライベートブラウジング認証をオフにする方法は? iPhoneのSafariでプライベートブラウジング認証をオフにする方法は? Nov 29, 2023 pm 11:21 PM

iOS 17 では、Apple はモバイル オペレーティング システムにいくつかの新しいプライバシーおよびセキュリティ機能を導入しました。その 1 つは、Safari のプライベート ブラウジング タブに対して 2 段階認証を要求する機能です。その仕組みとオフにする方法は次のとおりです。 iOS 17 または iPadOS 17 を実行している iPhone または iPad では、Safari でプライベート ブラウズ タブを開いていて、再度アクセスするためにセッションまたはアプリを終了する場合、Apple のブラウザでは Face ID/Touch ID 認証またはパスコードが必要になります。言い換えれば、ロックが解除されている iPhone または iPad を誰かが手に入れても、パスコードを知らなければプライバシーを閲覧することはできません。

golang WebSocketとJSONの組み合わせ:データ送信と解析を実現 golang WebSocketとJSONの組み合わせ:データ送信と解析を実現 Dec 17, 2023 pm 03:06 PM

golangWebSocket と JSON の組み合わせ: データ送信と解析の実現 現代の Web 開発では、リアルタイムのデータ送信がますます重要になっています。 WebSocket は双方向通信を実現するために使用されるプロトコルで、従来の HTTP リクエスト/レスポンス モデルとは異なり、WebSocket を使用すると、サーバーがクライアントにデータをアクティブにプッシュできます。 JSON (JavaScriptObjectNotation) は、簡潔で読みやすいデータ交換用の軽量形式です。

PHP 配列を JSON に変換するためのパフォーマンス最適化のヒント PHP 配列を JSON に変換するためのパフォーマンス最適化のヒント May 04, 2024 pm 06:15 PM

PHP 配列を JSON に変換するためのパフォーマンスの最適化方法には、JSON 拡張機能と json_encode() 関数の使用、文字エスケープを回避するためのバッファーの使用、およびサードパーティのエンコード結果の使用の検討が含まれます。 JSONエンコーディングライブラリ。

MySQL5.7とMySQL8.0の違いは何ですか? MySQL5.7とMySQL8.0の違いは何ですか? Feb 19, 2024 am 11:21 AM

MySQL5.7 と MySQL8.0 は 2 つの異なる MySQL データベース バージョンであり、それらの間には主な違いがいくつかあります: パフォーマンスの向上: MySQL8.0 では、MySQL5.7 と比較してパフォーマンスがいくつか向上しています。これには、より優れたクエリ オプティマイザー、より効率的なクエリ実行プランの生成、より優れたインデックス作成アルゴリズムと並列クエリなどが含まれます。これらの改善により、クエリのパフォーマンスとシステム全体のパフォーマンスが向上します。 JSON サポート: MySQL 8.0 では、JSON データのストレージ、クエリ、インデックス作成など、JSON データ型のネイティブ サポートが導入されています。これにより、MySQL での JSON データの処理と操作がより便利かつ効率的になります。トランザクション機能: MySQL8.0 では、アトミックなどのいくつかの新しいトランザクション機能が導入されています。

golang の json.MarshalIndent 関数を使用して、構造をフォーマットされた JSON 文字列に変換します。 golang の json.MarshalIndent 関数を使用して、構造をフォーマットされた JSON 文字列に変換します。 Nov 18, 2023 pm 01:59 PM

golang で json.MarshalIndent 関数を使用して、構造をフォーマットされた JSON 文字列に変換します。Golang でプログラムを作成するとき、多くの場合、構造を JSON 文字列に変換する必要があります。このプロセスでは、 json.MarshalIndent 関数が役に立ちます。フォーマットされた出力。以下では、この関数の使用方法と具体的なコード例を詳しく説明します。まず、データを含む構造体を作成しましょう。以下は目安です

PHP の json_encode() 関数を使用して、配列またはオブジェクトを JSON 文字列に変換し、出力をフォーマットします。 PHP の json_encode() 関数を使用して、配列またはオブジェクトを JSON 文字列に変換し、出力をフォーマットします。 Nov 03, 2023 pm 03:44 PM

PHP の json_encode() 関数を使用して配列またはオブジェクトを JSON 文字列に変換し、出力をフォーマットすると、異なるプラットフォームや言語間でのデータの転送や交換が容易になります。この記事では、json_encode() 関数の基本的な使い方と、JSON 文字列をフォーマットして出力する方法を紹介します。 1. json_encode() 関数の基本的な使い方 json_encode() 関数の基本的な構文は次のとおりです。

Jackson ライブラリのアノテーションは、JSON のシリアル化と逆シリアル化をどのように制御しますか? Jackson ライブラリのアノテーションは、JSON のシリアル化と逆シリアル化をどのように制御しますか? May 06, 2024 pm 10:09 PM

Jackson ライブラリのアノテーションは、JSON のシリアル化と逆シリアル化を制御します。 シリアル化: @JsonIgnore: プロパティを無視します @JsonProperty: 名前を指定します @JsonGetter: get メソッドを使用します @JsonSetter: set メソッドを使用します Deserialization: @JsonIgnoreProperties: プロパティ @ JsonProperty を無視します:名前を指定 @JsonCreator: コンストラクターを使用 @JsonDeserialize: カスタム ロジック

See all articles