Inheritance | yii\web\JsonParser |
---|---|
Implements | yii\web\RequestParserInterface |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/web/JsonParser.php |
Parses a raw HTTP request using yii\helpers\Json::decode()
To enable parsing for JSON requests you can configure yii\web\Request::$parsers using this class:
'request' => [ 'parsers' => [ 'application/json' => 'yii\web\JsonParser', ] ]
Property | Type | Description | Defined By |
---|---|---|---|
$asArray | boolean | Whether to return objects in terms of associative arrays. | yii\web\JsonParser |
$throwException | boolean | Whether to throw a yii\web\BadRequestHttpException if the body is invalid json | yii\web\JsonParser |
Method | Description | Defined By |
---|---|---|
parse() | Parses a HTTP request body. | yii\web\JsonParser |
Whether to return objects in terms of associative arrays.
public boolean $asArray = true
Whether to throw a yii\web\BadRequestHttpException if the body is invalid json
public boolean $throwException = true
Parses a HTTP request body.
public array parse ( $rawBody, $contentType ) | ||
---|---|---|
$rawBody | string |
The raw HTTP request body. |
$contentType | string |
The content type specified for the request body. |
return | array |
Parameters parsed from the request body |
throws | yii\web\BadRequestHttpException |
if the body contains invalid json and $throwException is |
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-web-jsonparser.html