当我尝试解码然后从ajax返回post数组时,我在symfony中一直收到同样的错误.
错误:
Response内容必须是实现__toString()的字符串或对象,给出"object".
500内部服务器错误 - UnexpectedValueException
PHP
public function ajaxAction(){
$array = $_POST['json'];
$arraydecode = json_decode($array);
return new Response($arraydecode);
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
您可以使用JsonResponse:http://symfony.com/doc/2.3/components/http_foundation/introduction.html#creating-a-json-response
use Symfony\Component\HttpFoundation\JsonResponse;
//some code
return new JsonResponse($array);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1760 次 |
| 最近记录: |