yii\web\JsonParser - Yii2 类参考手册
Class yii\web\JsonParser
Inheritance | yii\web\JsonParser |
---|---|
Implements | yii\web\RequestParserInterface |
Available since version | 2.0 |
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',
]
]
Public Properties
隐藏继承的属性 Hide inherited properties
属性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 |
Public Methods
隐藏继承的方法 Hide inherited methods
方法 Method | 简介 Description | 定义在 Defined By |
---|---|---|
parse() | Parses a HTTP request body. | yii\web\JsonParser |
属性详情 Property Details
Whether to return objects in terms of associative arrays.
Whether to throw a yii\web\BadRequestHttpException if the body is invalid json
方法详情 Method Details
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 |