php - Unable to convert Magento object array response to json format -
i trying convert magento object array json, giving result {}
.
$facetcolor = mage::getmodel('facets/color')->getcollection();
printing 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 use code convert json format:
$jsondata = mage::helper('core')->jsonencode((array)$facetcolor); echo $jsondata;
and result {}
.
i tried use json_encode
function, still no luck, same result.
try following :
$jsondata = mage::helper('core')->jsonencode($facetcolor->getdata());
or
$jsondata = json_encode($facetcolor->getdata());
hope helps!!
Comments
Post a Comment