我有以下存儲在我的數(shù)據(jù)庫中的 json 字符串:{"Monomeer5e68d7e547620":{"naam":"Monomeer","url":"https:\/\/website.nl\/new\/folie\/monomeer","afbeelding":"assets\/images\/noimg.jpg","aantal":"5","prijs":"2.28","totaalprijs":"20.4","hoogte":"20","breedte":"20","uploaden":"1","specificaties":"Array","controle":"1"},"Elastieken5e68d7e5477b6":{"naam":"Elastieken","url":"https:\/\/website.nl\/new\/folie\/monomeer","afbeelding":"assets\/images\/noimg.jpg","aantal":"1","prijs":"4.50","totaalprijs":"4.5","hoogte":"","breedte":"","uploaden":"0","specificaties":"","controle":""},"Tiewraps5e68d7e5477c8":{"naam":"Tiewraps","url":"https:\/\/website.nl\/new\/folie\/monomeer","afbeelding":"assets\/images\/noimg.jpg","aantal":"1","prijs":"9.95","totaalprijs":"9.95","hoogte":"","breedte":"","uploaden":"0","specificaties":"","controle":""}}它包含產(chǎn)品信息,否則將由如下所示的會話顯示:Array( [Monomeer5eeb62474c5ba] => Array ( [naam] => Monomeer [url] => https://website.nl/new/folie/monomeer [afbeelding] => assets/images/noimg.jpg [aantal] => 1 [hoogte] => 5 [breedte] => 11 [uploaden] => 1 [specificaties] => Array ( [Lijmlaag] => Array ( [waarde] => Wit ) [Laminaat] => Array ( [waarde] => Mat laminaat ) [Afwerking] => Array ( [waarde] => Contoursnijden ) ) [prijs] => 0.3355 [totaalprijs] => 0.3355 )當(dāng)會話過期時,我希望有人能夠再次查找他們的訂單信息,所以在顯示這個的頁面上我試圖建立一個檢查(查看會話是否存在,如果存在則循環(huán)會話,如果不循環(huán)在與會話完全相同的 php 數(shù)組上)。但是要獲得與我的會話相同的數(shù)組,它需要從 JSON 字符串轉(zhuǎn)換而來。我怎樣才能做到這一點(diǎn)?將上面的 JSON 字符串轉(zhuǎn)換為與我的 PHP 會話內(nèi)容看起來相同的 PHP 數(shù)組。
1 回答

冉冉說
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個贊
您必須使用函數(shù)的第二個參數(shù)json_decode
,它實(shí)際上會將您的 JSON 字符串解碼為數(shù)組,而不是 stdClass 對象。
$array?=?json_decode($json,?true);
從文檔:
json_decode?(?string?$json?[,?bool?$assoc?=?FALSE?[,?int?$depth?=?512?[,?int?$options?=?0?]]]?)?:?mixed
assoc當(dāng)為 TRUE 時,返回的對象將被轉(zhuǎn)換為關(guān)聯(lián)數(shù)組。
- 1 回答
- 0 關(guān)注
- 156 瀏覽
添加回答
舉報
0/150
提交
取消