WpOrg\Requests
Response::decode_body
JSON decode the response body.
The method parameters are the same as those for the PHP native json_decode() function.
Метод класса: Response{}
Хуков нет.
Возвращает
Массив.
Использование
$Response = new Response(); $Response->decode_body( $associative, $depth, $options );
- $associative(true|false|null)
- When
true, JSON objects will be returned as associative arrays; Whenfalse, JSON objects will be returned as objects. Whennull, JSON objects will be returned as associative arrays or objects depending on whetherJSON_OBJECT_AS_ARRAYis set in the flags.
По умолчанию:true(in contrast to the PHP native default ofnull) - $depth(int)
- Maximum nesting depth of the structure being decoded.
По умолчанию:512 - $options(int)
- Bitmask of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR.
По умолчанию:0(no options set)
Код Response::decode_body() Response::decode body WP 7.0
public function decode_body($associative = true, $depth = 512, $options = 0) {
$data = json_decode($this->body, $associative, $depth, $options);
if (json_last_error() !== JSON_ERROR_NONE) {
$last_error = json_last_error_msg();
throw new Exception('Unable to parse JSON data: ' . $last_error, 'response.invalid', $this);
}
return $data;
}