1
MODX CMS를 사용하여 제 3 자의 데이터를 출력하고 중첩 된 배열을 반환하는 방법에 대해 혼란 스럽습니다. 현재는 첫 번째 배열이나 NULL 만 반환합니다. 여기에 내가 사용하고있는 코드의 샘플입니다첫 번째 값만 반환하는 Datastream 배열
$datastream = '[{"id":57,
"offer_info":{"offer_headline":"Main Offer Headline",
"published_title":"Displayed Main Title"},
// My issue is here with the nested array
"service_categories":[{"service_category_code":"D",
"headline":"My Headline for D",
"midline":"Middle copy",
"footline":"Footer copy for D"},
{"service_category_code":"T",
"headline":"My Headline for T",
"image":"image.svg",
"footline":"Footer copy for T"}]}]';
$output_json = json_decode($datastream);
$output_json = json_decode($datastream, true); // this returns null for everything
foreach($output_json as $component) {
$productid = $component->id; // this returns ok
$offer_headline = $component->offer_info->offer_headline; // this returns ok
$published_title = $component->offer_info->published_title; // this returns ok
$service_categories_category_code = $component->service_categories[0]->service_category_code; // this only returns first value
$service_categories_category_code = $component->service_categories->service_category_code; // this returns NULL
var_dump($service_categories_category_code);
내가 확인 반환 값을 내 코드에 배치 할 수 있어요,하지만 중첩 된 배열의 첫 번째 값을 반환, 그리고 난 나는이 제대로 있는지 확인을하고있는 중이 야하지 않을 경우 :
if ($service_categories_category_code = "D") {
$d_details_headline = $component->service_categories[0]->headline;
$d_details_midline = $component->service_categories[0]->midline;
$d_footline = $component->service_categories[0]->footline;
} elseif ($service_categories_category_code = "T") {
$t_details_headline = $component->service_categories[0]->headline;
$t_details_image = $component->service_categories[0]->image;
$t_details_footline = $component->service_categories[0]->footline;
};
이 당신을하는 데 도움이 사전에 어떤 도움을
대단히 감사합니다. 이 문제를 해결하기 위해 올바른 길을 찾았습니다. 몇 줄을 더 추가해야했지만, 정확히 내가 필요한 것은 – Robert
입니다. 해피 코딩 – pradeep