I am working in Yii framework. I am having following function-
public function actionGetPublicPoll()
{
$model=new poll();
$polltype=Poll::model()->findAllByAttributes(array("pollTypeId"=>1));
foreach ($polltype as $poll)
{
if($poll->isActive==1 && $poll->isPublished==0)
{
echo "pollId is=".$poll->pollId;
$Id=$poll->pollId;
$option=Polloption::model()->findAllByAttributes(array("pollId"=>$poll->pollId));
foreach ($option as $option1)
{
echo $option1->optionId."</br>";
echo $option1->option;
$optionList[]=$option1->option;
}
}
}
echo CJSON::encode(array("PollId"=>$Id,"Question"=>$poll->pollQuestion,"options"=>$optionList));
}
So i am sending pollQuestion and its option in json format. From above,I am getting output as-
{"PollId":"3","Question":"Which is the biggest district in india ","options":["sachin tendulakar","Yuwraj singh","Rohit sharma","Mahendrasing dhoni"]}
But i want json in format:
{"PollId":"3","Question":"Which is the biggest district in india ","options":["option":"sachin tendulakar","option":"Yuwraj singh","option":"Rohit sharma","option":"Mahendrasing dhoni"]}
So what I need to modify? please help me….
Change
$optionList[]=$option1->option;to
$optionList[]=array('option'=>$option1->option);…………….
…………….
…………..
…………..
you will get
JSONas