通过jquery,我使用ajax/POST方式传输这个JSON。
{"indices":[1,2,6]}:
转换为Symfony2操作。目前我只关心数组,所以如果这样做可以使事情变得更容易,我也可以发布[1,2,6]。
如何将此转换为PHP对象?
不知何故,这不起作用:
/**
* @Route("/admin/page/applySortIndex", name="page_applysortindex")
* @Method("post")
* @Template()
*/
public function applySortIndexAction()
{
$request = $this->getRequest();
$j = json_decode($request->request->get('json'));
$indices = $j->indices;
return array('data'=> $indices);
}
提示:在.../PageController.php第64行尝试获取非对象属性(500内部服务器错误)。
问题出在我访问$j->indices时,$j似乎为空。
发帖者:
$.ajax({
type: 'POST',
url: "{{ path('page_applysortindex')}}",
data: $.toJSON({indices: newOrder}),
success: ...