dony  
          
              
                August 19, 2012,  9:10am
               
              1 
           
         
        
          Hello.
Explain to me why I get this error?
$posts = News::model()->findAll(array('select' => 'date'));
$jsons = CJSON::decode($posts);
foreach ($jsons as $json) {
    echo var_dump($json);
}
And I get
When I do so
$posts = News::model()->findAll(array('select' => 'date'));
foreach ($posts as $post) {
    echo var_dump(CJSON::decode($post));
}
I do not get this error. But I need decoded array of json assigned to a variable and transfer function. How to do it correctly?
         
        
           
         
            
       
      
        
          
          
            seenivasan  
          
              
                August 19, 2012,  9:20am
               
              2 
           
         
        
          Hope this helpful.
$posts = News::model()->findAll(array('select' => 'date'));
$arr=array();
foreach ($posts as $post) {
    $arr[]=CJSON::decode($post);
}
 
        
           
         
            
       
      
        
          
          
            Haensel  
          
              
                August 19, 2012,  2:45pm
               
              3 
           
         
        
          Ok, unless I am not missing something obvious you are confusing DEcoding with ENcoding. If you want your models to be serialized as a JSON string you’ll have to write
$jsonString=CJSON::encode($models);
Getting a php array out of a JSON string would mean
$phpArray=CJSON::decode($jsonString);