我正在尝试从PHP变量中的以下JSON数组获取值。
这是数组的var_dump:
array(3) { ["id"]=> string(2) "14" ["css"]=> string(400) "" ["json"]=> string(4086) " { "Canvas": [ { "MainObjects": { "After Participation": { "afterParticipationHeader": "Thank you!" }, "Invite Friends": { "InviteHeadline": "", "InviteMsg": "", "InviteImg": "" } }, "QuizModule": { "Questions": [], "Submit_Fields": [ { "label": "Name", "name": "txtName", "value": true } ] } } ] }" }
我可以像这样在PHP中获取[“ json”]的值:
$json = $data[0]['json'];
但是,如何从“ json”内部的数组中获取值,例如“ AfterParticipationHeader”。和“ Submit_Fields”?
首先,您必须解码json数据
$json = json_decode($data[0]['json']);
然后您可以访问 AfterParticipationHeader
AfterParticipationHeader
$json->Canvas[0]->MainObjects->{"After Participation"}->afterParticipationHeader