当我请求xml时,我的 XML输出看起来很奇怪. 控制器: use FOS\RestBundle\Controller\Annotations as REST;class RestController { /** * @REST\View */ public function getAgenciesAction() { return array("bb"=array('zz'='vv'),'zz');
控制器:
use FOS\RestBundle\Controller\Annotations as REST; class RestController { /** * @REST\View */ public function getAgenciesAction() { return array("bb"=>array('zz'=>'vv'),'zz'); } }
请求标题:
Aceept:application / xml
响应:
<?xml version="1.0" encoding="UTF-8"?> <result> <entry> <entry><![CDATA[vv]]></entry> </entry> <entry><![CDATA[zz]]></entry> </result>
为什么只返回结束节点而不是所有键和值?
FOSRestBundle中的xml序列化程序不使用密钥序列化数组.每个数组条目将作为< entry>结果在响应中,无论关键.示例中的输出是正确的.键仅在json输出中相关.序列化实体具有正确的输出,因为该字段将导致< field>值< / field>
示例控制器
/** * @ApiDoc( * description="Returns the own user details", * statusCodes={ * 200="Returned when successful", * 403="Returned when missing permissions", * } * ) * * @Rest\Get("/users/me") * @Rest\View(serializerGroups={"details"}) */ public function getMeAction() { $user = $this->getUser(); return array('user' => $user); }
和响应.您看,关键用户输出为< entry>.
<?xml version="1.0" encoding="UTF-8"?> <result> <entry> <id><![CDATA[517781e2e707a00217000000]]></id> <username><![CDATA[admin]]></username> <email><![CDATA[admin@example.com]]></email> <company><![CDATA[acme]]></company> </entry> </result>