我有以下存储在我的数据库中的 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":""}}它包含产品信息,否则将由如下所示的会话显示: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 )当会话过期时,我希望有人能够再次查找他们的订单信息,所以在显示这个的页面上我试图建立一个检查(查看会话是否存在,如果存在则循环会话,如果不循环在与会话完全相同的 php 数组上)。但是要获得与我的会话相同的数组,它需要从 JSON 字符串转换而来。我怎样才能做到这一点?将上面的 JSON 字符串转换为与我的 PHP 会话内容看起来相同的 PHP 数组。
1 回答
冉冉说
TA贡献1877条经验 获得超1个赞
您必须使用函数的第二个参数json_decode
,它实际上会将您的 JSON 字符串解码为数组,而不是 stdClass 对象。
$array = json_decode($json, true);
从文档:
json_decode ( string $json [, bool $assoc = FALSE [, int $depth = 512 [, int $options = 0 ]]] ) : mixed
assoc当为 TRUE 时,返回的对象将被转换为关联数组。
- 1 回答
- 0 关注
- 125 浏览
添加回答
举报
0/150
提交
取消