json_decode 與 json_encode

來源:互聯網
上載者:User

標籤:die   索引數組   escape   ali   nbsp   bsp   parameter   name   soc   

一:json_decode ( string $json [, bool $assoc=FALSE [, int $depth= 512 [, int $options= 0 ]]])

①:$json解析編碼為UTF-8編碼的字串

②:$assoc:當該參數為 TRUE 時,將返回數組,FALSE 時返回對象

③:$depth 為遞迴深度

④:$options   JSON解碼選項的位元遮罩。目前有兩種支援的選項。第一個是JSON_BIGINT_AS_STRING允許將大整數轉換為字串而不是浮點數,這是預設值。第二個選項是JSON_OBJECT_AS_ARRAY ,它和設定相同的效果assoc來 TRUE。

json_encode()只將索引數組(indexed array)轉為數組格式,而將關聯陣列(associative array)轉為對象格式。

 

二:json_encode  不轉義中文漢字的方法

json_encode($data, JSON_UNESCAPED_UNICODE); //必須PHP5.4+ 

①:$array = array(‘lixi‘=>‘李茜‘);  var_dump(json_encode($array,JSON_UNESCAPED_UNICODE));die;    列印得到  string(17) "{"lixi":"李茜"}"

②:$array = array(‘lixi‘=>‘李茜‘);  var_dump(json_encode($array));die;   列印得到  string(23) "{"lixi":"\u674e\u831c"}"

json_decode 與 json_encode

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.