简体   繁体   English

FOSRestBundle:如何在我的Rest Api中将数组设置为URL

[英]FOSRestBundle: How to set an array to an URL in my Rest Api

I have my RestBundle in Symfony and I want to send an array in my api-url-call: 我在Symfony中拥有RestBundle,我想在我的api-url-call中发送一个数组:

@Annotations\QueryParam(
     *   name = "codes",
     *   array = true,
     *   nullable = false,
     * )

But when i put an url-encoded array in my link for example: 但是当我在链接中放置一个URL编码的数组时,例如:

...0%5BcodeId%5D=443&0%5Bcode%5D=AAA222&1%5BcodeId%5D=443&1%5Bcode%5D=BBB222&2%5BcodeId%5D=443&2%5Bcode%5D=ABC123

It says that there is an array instead of as string. 它说有一个数组而不是字符串。 But how do I set an array into a link? 但是,如何将数组设置为链接?

Try this way: 尝试这种方式:

    "...%5BcodeId%5D%5B0%5D=443&%5Bcode%5D%5B0%5D=AAA222&%5BcodeId%5D%5B1%5D=443&%5Bcode%5D%5B1%5D=BBB222&%5BcodeId%5D%5B2%5D=443&%5Bcode%5D%5B2%5D=ABC123"

Decoded: 解码:

...[codeId][0]=443&[code][0]=AAA222&[codeId][1]=443&[code][1]=BBB222&[codeId][2]=443&[code][2]=ABC123

If useful, have a look at the examples using a Param fetcher listener: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/3-listener-support.rst 如果有用,请使用Param Fetcher侦听器查看示例: https : //github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/3-listener-support.rst

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM