Class yii\web\JsonParser
| 继承 | yii\web\JsonParser |
|---|---|
| 实现 | yii\web\RequestParserInterface |
| 可用版本自 | 2.0 |
| 源码 | https://github.com/yiichina/yii2/blob/api/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',
]
]
公共属性
| 属性 | 类型 | 描述 | 被定义在 |
|---|---|---|---|
| $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 |
属性详情
Whether to return objects in terms of associative arrays.
Whether to throw a yii\web\BadRequestHttpException if the body is invalid json
方法详情
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 |