共計 337 個字符,預(yù)計需要花費 1 分鐘才能閱讀完成。
您可以使用 json_decode()
函數(shù)將 JSON 字符串轉(zhuǎn)換為數(shù)組。示例代碼如下:
$jsonString = '{"name":"John", "age":30, "city":"New York"}';
$array = json_decode($jsonString, true);
// 輸出數(shù)組
print_r($array);
這將輸出以下結(jié)果:
Array
([name] => John
[age] => 30
[city] => New York
)
在 json_decode()
函數(shù)中,第一個參數(shù)是要轉(zhuǎn)換的 JSON 字符串,第二個參數(shù)是一個可選的布爾值,用于指定是否將 JSON 對象轉(zhuǎn)換為關(guān)聯(lián)數(shù)組。如果第二個參數(shù)為true
,則將返回關(guān)聯(lián)數(shù)組,否則將返回對象。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完