我在 Yii 框架中工作。我有以下功能-
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));
}
所以我正在发送pollQuestion
及其json
格式选项。从上面,我得到的输出为-
{"PollId":"3","Question":"Which is the biggest district in india ","options":["sachin tendulakar","Yuwraj singh","Rohit sharma","Mahendrasing dhoni"]}
但我想要 json 格式:
{"PollId":"3","Question":"Which is the biggest district in india ","options":["option":"sachin tendulakar","option":"Yuwraj singh","option":"Rohit sharma","option":"Mahendrasing dhoni"]}
那么我需要修改什么?请帮我....