Reputation: 95
I am trying to convert a magento object array to json, but it is giving the result {}
.
$facetColor = Mage::getModel('facets/color')->getCollection();
printing the array gives me
print "<pre>";
print_r($facetColor);
gamer_Facets_Model_Resource_Color_Collection Object
(
[_joinedFields:protected] => Array
(
)
[_model:protected] => facets/color
[_resourceModel:protected] => facets/color
[_resource:protected] => Gamer_Facets_Model_Resource_Color Object
(
[_resources:protected] => Mage_Core_Model_Resource Object
(
[_connectionTypes:protected] => Array
(
)
[_connections:protected] => Array
(
[core_read] => Varien_Db_Adapter_Pdo_Mysql Object
(
[_defaultStmtClass:protected] => Varien_Db_Statement_Pdo_Mysql
[_transactionLevel:protected] => 0
[_connectionFlagsSet:protected] => 1
[_ddlCache:protected] => Array
(
[1] => Array
(
[log_visitor_info] => Array
(
[visitor_id] => Array
(
[SCHEMA_NAME] =>
[TABLE_NAME] => log_visitor_info
[COLUMN_NAME] => visitor_id
[COLUMN_POSITION] => 1
[DATA_TYPE] => bigint
[DEFAULT] => 0
[NULLABLE] =>
[LENGTH] =>
[SCALE] =>
[PRECISION] =>
[UNSIGNED] => 1
[PRIMARY] => 1
[PRIMARY_POSITION] => 1
[IDENTITY] =>
)
[http_referer] => Array
(
[SCHEMA_NAME] =>
[TABLE_NAME] => log_visitor_info
[COLUMN_NAME] => http_referer
[COLUMN_POSITION] => 2
[DATA_TYPE] => varchar
[DEFAULT] =>
[NULLABLE] => 1
[LENGTH] => 255
[SCALE] =>
[PRECISION] =>
[UNSIGNED] =>
[PRIMARY] =>
[PRIMARY_POSITION] =>
[IDENTITY] =>
)
then i use this code to convert it into the json format:
$jsonData = Mage::helper('core')->jsonEncode((array)$facetColor);
echo $jsonData;
and get the result {}
.
I also tried to use the json_encode
function, but still no luck, same result.
Upvotes: 0
Views: 3405
Reputation: 941
Try following :
$jsonData = Mage::helper('core')->jsonEncode($facetColor->getData());
or
$jsonData = json_encode($facetColor->getData());
Hope this helps!!
Upvotes: 2