亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

??
一、使用 json_encode 輸出
二、使用 jsonFormat 輸出
三、php5.4 以后,json_encode增加了JSON_UNESCAPED_UNICODE , JSON_PRETTY_PRINT 等幾個常量參數(shù)。使顯示中文與格式化更方便。
? ??? ?? PHP ???? PHP JSON ??? ???(??) ??

PHP JSON ??? ???(??) ??

Oct 16, 2019 am 10:52 AM
json ??? ??

PHP JSON ??? ???(??) ??

一、使用 json_encode 輸出

<?php
header(&#39;content-type:application/json;charset=utf8&#39;);
$arr = array(
    &#39;status&#39; => true,
    &#39;errMsg&#39; => &#39;&#39;,
    &#39;member&#39; =>array(
        array(
            &#39;name&#39; => &#39;李&#39;,
            &#39;gender&#39; => &#39;男&#39;
        ),
        array(
            &#39;name&#39; => &#39;趙&#39;,
            &#39;gender&#39; => &#39;女&#39;
        )
    )
);
  
echo json_encode($arr);
?>

(推薦學習:PHP視頻教程

輸出:

{"status":true,"errMsg":"","member":[{"name":"\u674e","gender":"\u7537"},{"name":"\u8d75","gender":"\u5973"}]}

二、使用 jsonFormat 輸出

<?php
  
/** Json數(shù)據(jù)格式化
* @param  Mixed  $data   數(shù)據(jù)
* @param  String $indent 縮進字符,默認4個空格
* @return JSON
*/
function jsonFormat($data, $indent=null){
  
    // 對數(shù)組中每個元素遞歸進行urlencode操作,保護中文字符
    array_walk_recursive($data, &#39;jsonFormatProtect&#39;);
  
    // json encode
    $data = json_encode($data);
  
    // 將urlencode的內(nèi)容進行urldecode
    $data = urldecode($data);
  
    // 縮進處理
    $ret = &#39;&#39;;
    $pos = 0;
    $length = strlen($data);
    $indent = isset($indent)? $indent : &#39;    &#39;;
    $newline = "\n";
    $prevchar = &#39;&#39;;
    $outofquotes = true;
  
    for($i=0; $i<=$length; $i++){
  
        $char = substr($data, $i, 1);
  
        if($char==&#39;"&#39; && $prevchar!=&#39;\\&#39;){
            $outofquotes = !$outofquotes;
        }elseif(($char==&#39;}&#39; || $char==&#39;]&#39;) && $outofquotes){
            $ret .= $newline;
            $pos --;
            for($j=0; $j<$pos; $j++){
                $ret .= $indent;
            }
        }
  
        $ret .= $char;
         
        if(($char==&#39;,&#39; || $char==&#39;{&#39; || $char==&#39;[&#39;) && $outofquotes){
            $ret .= $newline;
            if($char==&#39;{&#39; || $char==&#39;[&#39;){
                $pos ++;
            }
  
            for($j=0; $j<$pos; $j++){
                $ret .= $indent;
            }
        }
  
        $prevchar = $char;
    }
  
    return $ret;
}
  
/** 將數(shù)組元素進行urlencode
* @param String $val
*/
function jsonFormatProtect(&$val){
    if($val!==true && $val!==false && $val!==null){
        $val = urlencode($val);
    }
}
  
header(&#39;content-type:application/json;charset=utf8&#39;);
  
$arr = array(
    &#39;status&#39; => true,
    &#39;errMsg&#39; => &#39;&#39;,
    &#39;member&#39; =>array(
        array(
            &#39;name&#39; => &#39;李&#39;,
            &#39;gender&#39; => &#39;男&#39;
        ),
        array(
            &#39;name&#39; => &#39;趙&#39;,
            &#39;gender&#39; => &#39;女&#39;
        )
    )
);
  
echo jsonFormat($arr);
  
?>

輸出:

{
    "status":true,
    "errMsg":"",
    "member":[
        {
            "name":"李",
            "gender":"男"
        },
        {
            "name":"趙",
            "gender":"女"
        }
    ]
}

三、php5.4 以后,json_encode增加了JSON_UNESCAPED_UNICODE , JSON_PRETTY_PRINT 等幾個常量參數(shù)。使顯示中文與格式化更方便。

<?php
header(&#39;content-type:application/json;charset=utf8&#39;);   
$arr = array(  
    &#39;status&#39; => true,  
    &#39;errMsg&#39; => &#39;&#39;,  
    &#39;member&#39; =>array(  
        array(  
            &#39;name&#39; => &#39;李&#39;,  
            &#39;gender&#39; => &#39;男&#39;  
        ),  
        array(  
            &#39;name&#39; => &#39;趙&#39;,  
            &#39;gender&#39; => &#39;女&#39;  
        )  
    )  
);
echo json_encode($arr, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);

輸出:

{
    "status": true,
    "errMsg": "",
    "member": [
        {
            "name": "李",
            "gender": "男"
        },
        {
            "name": "趙",
            "gender": "女"
        }
    ]
}

? ??? PHP JSON ??? ???(??) ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? 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

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1597
29
PHP ????
1488
72
???
PHP ??? JSON?? ???? ?? ?? ??? ? PHP ??? JSON?? ???? ?? ?? ??? ? May 04, 2024 pm 06:15 PM

PHP ??? JSON?? ???? ?? ?? ??? ??? ??? ????. JSON ?? ? json_encode() ??? ???? ?? ?????? ???? ??? ???? JSON ??? ?? ??? ?????. JSON ??? ?????.

JSON ???? Golang? ??????? ???? ??? ?????? JSON ???? Golang? ??????? ???? ??? ?????? Jun 06, 2024 am 11:24 AM

JSON ???? gjson ????? ?? json.Unmarshal ??? ???? MySQL ??????? ??? ? ????. gjson ?????? JSON ??? ?? ???? ??? ??? ????, json.Unmarshal ???? JSON ???? ?????? ?? ?? ?? ???? ?????. ? ?? ?? SQL ?? ???? ?? ??? ???? ???? ??????? ???? ???.

Jackson ?????? ??? JSON ??? ? ????? ??? ?????? Jackson ?????? ??? JSON ??? ? ????? ??? ?????? May 06, 2024 pm 10:09 PM

Jackson ?????? ??? JSON ??? ? ????? ?????. ???: @JsonIgnore: ?? ?? @JsonProperty: ?? ?? @JsonGetter: get ??? ?? @JsonSetter: set ??? ?? ????: @JsonIgnoreProperties: @JsonProperty ?? ??: ?? ?? @JsonCreator: ??? ?? @JsonDeserialize: ??? ?? ??

?? ???? ?? ?? ?? ???? ?? ?? Mar 19, 2024 pm 08:31 PM

??? ?? ??? ??? ? ?? ??? ?? ???? ???? ???? ???. ??? ?? ??? ???? ?? ???? ??? ??? ?? ????? ??? ? ??? ????? ?????. ??, ? ?? ??? ?? ??? ? ???? ?? ? ????. ?? ?? ?? ??, ??? ?? ?? ?? ?? ??? ? ???? ?? ? ????. ???? ??? ??? ??? ?? ??? ?? ???? ??? ?????. ?? ?????! ?? ? Word ??? ?? [?] ??? [??] ??? ????. ?? ?? ???? ??? ???? ??? ?? [???] ??? ?????. 2. ???? ???? ???? ???? ?? ??? ?????.

PHP ??? ???? JSON ???? ???? ??? ?????? PHP ??? ???? JSON ???? ???? ??? ?????? May 04, 2024 pm 03:21 PM

PHP? JSON ???? ???? ?? ?? ??? ?????. JSON ??? ?? ??: json_decode()? ???? JSON ???? PHP ??? ?????. JSON ??? ??: json_encode()? ???? PHP ?? ?? ??? JSON ???? ?????. JSON ???? ?? ? ????: PHP ?? ??? ???? ?-? ? ?? ?? ??? ?? ?? ?? ??????.

PHP ??? JSON?? ???? ?? ?? ? PHP ??? JSON?? ???? ?? ?? ? May 03, 2024 pm 06:33 PM

PHP ??? json_encode() ??? ?? JSON ???? ??? ? ???(?: $json=json_encode($array);), ??? json_decode() ??? ???? JSON?? ??? ??? ? ????($array= json_decode($json);) . ?? ??? ?? ?? ??, ??? ?? ?? ?? ? ?? ????? ??? ?????.

Java JSON ??? ??? ?????: ??? ??? ?? ?? ? ?? Java JSON ??? ??? ?????: ??? ??? ?? ?? ? ?? Mar 09, 2024 am 09:13 AM

JSON ??? ?? ?? JSON ??? ?? ??? ??? ???? ???? ? ??? ?????. Java??? ?? ??? ??? ? ????. Gson ????? ??: Gson? ??? ?? ???? ???? API? ???? ?? ???? json ?? ?? ????????. Gsongson=newGson();JsonObjectjsonObject=gson.fromJson(jsonString ,JsonObject .class); Jackson ????? ??: Jackson? ??? ?? ??? ??? ?? ??(?: XML)??? ??? ???? ? ?? ?? ?? JSON ?? ????????.

JSON? ???? RSS ??? ????? JSON? ???? RSS ??? ????? Apr 10, 2025 am 09:31 AM

JSONFEED? JSON ?? RSS ???? ???? ?? ???? ?? ??? ????. 1) JSONFEED? JSON ??? ???? ?? ? ?? ??? ????. 2) ?? ??? ???? ?? ? ??? ?????. 3) JSONFEED? ???? ??? ?? ???? ??? ??? ?? ? ? ????.

See all articles