如何反序列化ArrayObject

时间:2010-01-04 04:23:17

标签: php

注意:我尝试过使用unserialize函数,但是它说第一个参数应该是一个字符串而不是一个Object,所以我的问题 -

问:如何在php中反序列化ArrayObject,我的ArrayObject包含:

O:11:"ArrayObject":2:{s:14:"shoppingBasket";a:1:{s:6:"offers";a:2:{i:10;a:8:{s:9:"object_id";s:2:"10";s:6:"family";s:8:"Internet";s:8:"is_unica";b:1;s:10:"offer_type";s:6:"Atomic";s:24:"product_specification_id";s:6:"134455";s:20:"contract_constraints";a:5:{s:19:"min_contract_period";s:1:"1";s:13:"notice_period";s:2:"12";s:15:"rollover_period";s:1:"1";s:18:"right_of_wd_period";s:1:"1";s:19:"cancellation_period";s:6:"ALWAYS";}s:15:"financial_terms";a:3:{s:14:"billing_period";a:2:{i:0;s:6:"YEARLY";i:1;s:9:"QUARTERLY";}s:14:"payment_method";a:1:{i:0;s:12:"DIRECT_DEBIT";}s:17:"bill_presentation";a:1:{i:0;s:5:"PAPER";}}s:6:"prices";a:1:{i:25;a:1:{s:9:"object_id";s:2:"25";}}}i:11224;a:8:{s:9:"object_id";s:5:"11224";s:6:"family";s:8:"Internet";s:8:"is_unica";b:0;s:10:"offer_type";s:11:"DOUBLE_PLAY";s:24:"product_specification_id";s:5:"32567";s:20:"contract_constraints";a:5:{s:19:"min_contract_period";s:1:"8";s:13:"notice_period";s:1:"2";s:15:"rollover_period";s:1:"6";s:18:"right_of_wd_period";s:1:"1";s:19:"cancellation_period";s:12:"END_OF_MONTH";}s:15:"financial_terms";a:3:{s:14:"billing_period";a:2:{i:0;s:6:"YEARLY";i:1;s:9:"QUARTERLY";}s:14:"payment_method";a:1:{i:0;s:12:"DIRECT_DEBIT";}s:17:"bill_presentation";a:1:{i:0;s:5:"PAPER";}}s:6:"prices";a:0:{}}}}s:15:"recommendations";a:1:{i:10017;a:7:{s:9:"object_id";s:5:"10017";s:10:"offer_type";s:6:"Atomic";s:6:"family";s:0:"";s:8:"is_unica";b:0;s:15:"financial_terms";a:3:{s:14:"billing_period";a:1:{i:0;s:9:"QUARTERLY";}s:14:"payment_method";a:1:{i:0;s:12:"DIRECT_DEBIT";}s:17:"bill_presentation";a:1:{i:0;s:5:"PAPER";}}s:20:"contract_constraints";a:5:{s:19:"min_contract_period";i:24;s:19:"cancellation_period";s:6:"ALWAYS";s:13:"notice_period";i:3;s:15:"rollover_period";i:2;s:18:"right_of_wd_period";i:1;}s:6:"prices";a:1:{i:99;a:1:{s:9:"object_id";s:2:"99";}}}}}

这是给出这个序列化输出的代码,我想反序列化它。

private function associateCollateral($entities)
            {
                    //var_dump($entities);

                    // Extract all object ids from the given set of ids, and pass into the getContentId.
                    $content_ids = $this->getCollateralDao()->getContentId(array_keys($entities->offsetGet('recommendations')));
                    // Call to CMS to get collateral content.
                    /*foreach($content_ids as $content_id)
                    {
                             $contentObj = CmsObjectHandler::get(OBJECT_TYPE_CONTENT,$content_id);
                             $content = $contentObj->getContent();
                             $result += $content;
                             echo"Here \n";
                             print_r($result)."\n";
                             //exit();
                    }*/
                    var_dump($entities);  ---STEP1
                    return $entities;     ---STEP2
                    //var_dump($entities);  ---STEP3
                    //exit();
            }

步骤2返回序列化输出,现在我想反序列化它。

1 个答案:

答案 0 :(得分:0)

更新

K,所以我试过了:

$something = '/*(enter your string here)*/';

echo print_r(unserialize($something));

它像一个像它应该的数组对象一样出现。只是确保你传递的是unserialize arrayObject的字符串表示而不是arrayObject本身。