JsonParser
in package
implements
RequestParserInterface
Parses a raw HTTP request using [[\yii\helpers\Json::decode()]].
To enable parsing for JSON requests you can configure [[Request::parsers]] using this class:
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
]
Tags
Table of Contents
Interfaces
- RequestParserInterface
- Interface for classes that parse the raw request body into a parameters array.
Properties
- $asArray : bool
- $throwException : bool
Methods
- parse() : array<string|int, mixed>|stdClass
- Parses a HTTP request body.
Properties
$asArray
public
bool
$asArray
= true
whether to return objects in terms of associative arrays.
$throwException
public
bool
$throwException
= true
whether to throw a [[BadRequestHttpException]] if the body is invalid JSON
Methods
parse()
Parses a HTTP request body.
public
parse(string $rawBody, string $contentType) : array<string|int, mixed>|stdClass
Parameters
- $rawBody : string
-
the raw HTTP request body.
- $contentType : string
-
the content type specified for the request body.
Tags
Return values
array<string|int, mixed>|stdClass —parameters parsed from the request body