dongyuan2652 2015-06-19 04:56
浏览 62
已采纳

无法将Magento对象数组响应转换为json格式

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.

  • 写回答

1条回答 默认 最新

  • duankan6894 2015-06-19 05:00
    关注

    Try following :

    $jsonData = Mage::helper('core')->jsonEncode($facetColor->getData());
    

    or

    $jsonData = json_encode($facetColor->getData());

    Hope this helps!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?