php json 轉 數組 Array

來源:互聯網
上載者:User

以前轉了一篇  php json轉 array 的文章。覺的寫的還不錯, 但是最近發現 php 內建函數的轉換方法,

在這裡提供出來給大家分享一下,對看過我以前轉的那篇文章的同志們表示歉意,把你們帶溝裡了

json對象轉成 普通數組 也就是 Array 的最簡單方法還是 用 json_decode() 方法,只需要在後面多寫一個參數就可以搞定

json_decode($json,true);

這樣就可以將 json 轉換成數組形式了,key 保持原來格式

$json = '{"name":"zhangsan","age":20,"sex":"nan"}';

print_r(json_decode($json,true));

這樣的json資料解析後 就會成為下面這樣的數組

Array
(
    [name] => zhangsan
    [age] => 20
    [sex] => nan
)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.