0
我是Silex中的新手,我嘗試使用POST檢索嵌套的Json數據。這是Json的一部分。與Silex POST嵌套的Json
{
"action": "opened",
"number": 3,
"pull_request": {
"id": 35845110,
"number": 3,
"state": "open",
"locked": false,
"title": "Kie"
}
}
我的代碼工作的行動,數量和pull_request,但我只是想使用pull_request數據狀態,我不知道如何收集它。
$app->before(function (Request $request) {
if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
$data =json_decode($request->getContent(), true);
$request->request->replace(is_array($data) ? $data : array());
}
});
$app->post('/api', function(Request $request) use ($app) {
$pullRequest = array(
'action' => $request->request->get('action'),
'number' => $request->request->get('number'),
'pull_request' => $request->request->get('pull_request'),
'state' => $request->request->get('state')
);
return $app->json($pullRequest,201);
});
感謝您的幫助
就是這樣,謝謝老兄 – CorentinDodon