2010-01-04 62 views
0

注意:我使用反序列化功能都試過,但它說,第一個參數應該是一個字符串,而不是一個對象,所以我的問題 -如何反序列化的ArrayObject的

問:我如何反序列化的ArrayObject的在PHP中,我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步返回序列化的輸出,現在我想反序列化它。

回答

0

UPDATE

K,所以我想這:

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

echo print_r(unserialize($something)); 

而且它出來作爲一個ArrayObject的喜歡它應該。只要確保你通過unserialize arrayObject的字符串表示而不是arrayObject本身。

+0

我已經添加了大量的代碼,它返回序列化的數據,現在我想反序列化它。 – Rachel 2010-01-04 04:44:17

+0

Rachel。這是你的其他問題的延伸 http://stackoverflow.com/questions/1997156/php-error-vardumpa-shows-different-value-and-return-a-prints-out-different/1997243#1997243 。首先找到數據序列化的位置並解決該問題。通過試圖迴避你解決它只是避免它的問題,但類似的問題將彈出,你會回到 – DeveloperChris 2010-01-04 05:06:05

+0

@DC:我試過,但沒有var_dump,回聲或print_r這樣會打印出序列化的數據輸出。我會再次通過它並更新。 – Rachel 2010-01-04 05:15:53