Answer the question
In order to leave comments, you need to log in
How to convert an array to json in Bitrix?
I can’t convert to json, I try, but it didn’t work json_encode($prop, JSON_FORCE_OBJECT);
$prop = Array
(
[0] => Array
(
[NAME] => ИДН 500 - средний элемент
[PREVIEW_PICTURE] => /upload/iblock/501/IDN_500_S_2.jpg
[PRICE] => 1575.00
)
[1] => Array
(
[NAME] => ИДН 500 - концевой элемент
[PREVIEW_PICTURE] => /upload/iblock/c2c/IDN_500_K_2.jpg
[PRICE] => 788.00
)
)
<? require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
if(!CModule::IncludeModule("iblock"))
return;
$idarr = $_POST;
$prop = array();
$count = 0;
foreach ($_POST as $id){
$res = CIBlockElement::GetByID(+$id);
if($ar_res = $res->GetNext()) {
$prop[$count]['NAME'] = $ar_res['NAME'];
$prop[$count]['PREVIEW_PICTURE'] = CFile::GetPath($ar_res['PREVIEW_PICTURE']);
$prop[$count]['PRICE'] = CPrice::GetBasePrice($ar_res['ID'])['PRICE'];
}
$count++;
}
echo \Bitrix\Main\Web\Json::encode($prop);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question