Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

How to convert json Request to an array in symfony?

$
0
0

I am trying to convert the JSON Request $request to an array.

I have output something like this:

^ Symfony\Component\HttpFoundation\Request {#45+attributes: Symfony\Component\HttpFoundation\ParameterBag {#74    #parameters: array:3 ["_route" => "app_movie_create""_controller" => "App\Controller\MovieController::create""_route_params" => []    ]  }+request: Symfony\Component\HttpFoundation\ParameterBag {#96    #parameters: []  }+query: Symfony\Component\HttpFoundation\ParameterBag {#69    #parameters: array:1 ["title" => "Homecoming"    ]  }

I have seen some tutorials giving following solutions.

 $data = json_decode($request->getContent(), true);        if (json_last_error() !== JSON_ERROR_NONE) {            throw new BadRequestHttpException('invalid json body: ' . json_last_error_msg());        }

But I am getting null in my case.

I can do like this. $request->get('title');


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>