本文整理匯總了PHP中Helpers::jsonDecode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Helpers::jsonDecode方法的具體用法?PHP Helpers::jsonDecode怎麽用?PHP Helpers::jsonDecode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Helpers
的用法示例。
在下文中一共展示了Helpers::jsonDecode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: processRequestParams_json
protected function processRequestParams_json($_data)
{
return Helpers::jsonDecode($_data, 500);
}
示例2: decode
/**
* @param Http\Response
* @param array|NULL these codes are treated as success; code < 300 if NULL
* @return mixed
*
* @throws ApiException
*/
public function decode(Http\Response $response, array $okCodes = NULL)
{
$content = $response->getContent();
if (preg_match('~application/json~i', $response->getHeader('Content-Type', ''))) {
try {
$content = Helpers::jsonDecode($response->getContent());
} catch (JsonException $e) {
throw new InvalidResponseException('JSON decoding failed.', 0, $e, $response);
}
if (!is_array($content) && !is_object($content)) {
throw new InvalidResponseException('Decoded JSON is not an array or object.', 0, NULL, $response);
}
}
$code = $response->getCode();
if ($okCodes === NULL && $code >= 300 && $code != 304 || is_array($okCodes) && !in_array($code, $okCodes)) {
/** @var $content \stdClass */
switch ($code) {
case Http\Response::S400_BAD_REQUEST:
throw new BadRequestException($content->message, $code, NULL, $response);
case Http\Response::S401_UNAUTHORIZED:
throw new UnauthorizedException($content->message, $code, NULL, $response);
case Http\Response::S403_FORBIDDEN:
if ($response->getHeader('X-RateLimit-Remaining') === '0') {
throw new RateLimitExceedException($content->message, $code, NULL, $response);
}
throw new ForbiddenException($content->message, $code, NULL, $response);
case Http\Response::S404_NOT_FOUND:
throw new NotFoundException('Resource not found or not authorized to access.', $code, NULL, $response);
case Http\Response::S422_UNPROCESSABLE_ENTITY:
$message = $content->message . implode(', ', array_map(function ($error) {
return '[' . implode(':', (array) $error) . ']';
}, $content->errors));
throw new UnprocessableEntityException($message, $code, NULL, $response);
}
$message = $okCodes === NULL ? '< 300' : implode(' or ', $okCodes);
throw new UnexpectedResponseException("Expected response with code {$message}.", $code, NULL, $response);
}
return $content;
}
示例3: sendRequest_decodeData_json
public function sendRequest_decodeData_json($_data)
{
return Helpers::jsonDecode($_data);
}