本文整理汇总了PHP中Services_JSON::isError方法的典型用法代码示例。如果您正苦于以下问题:PHP Services_JSON::isError方法的具体用法?PHP Services_JSON::isError怎么用?PHP Services_JSON::isError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Services_JSON
的用法示例。
在下文中一共展示了Services_JSON::isError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decodeJson
/**
* JSON 形式の文字列を値に変換します。
*
* @param string $json
* @param bool $returnAssoc
* @throws RuntimeException
* @return mixed
*/
public static function decodeJson($json, $returnAssoc = false)
{
if (function_exists('json_decode') && function_exists('json_last_error')) {
$native = json_decode($json, $returnAssoc);
$error = json_last_error();
if ($error !== JSON_ERROR_NONE) {
$message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'error code: ' . $error;
throw new RuntimeException($message, $error);
}
return $native;
}
// オートローダーを働かせて定数を定義させる。
class_exists('Services_JSON');
$options = $returnAssoc ? SERVICES_JSON_LOOSE_TYPE : 0;
$decoder = new Services_JSON($options);
$native = $decoder->decode($json);
if (Services_JSON::isError($json)) {
throw new RuntimeException($native->toString(), $native->getCode());
}
return $native;
}
示例2: name_value
/**
* array-walking function for use in generating JSON-formatted name-value pairs
*
* @param string $name name of key to use
* @param mixed $value reference to an array element to be encoded
*
* @return string JSON-formatted name-value pair, like '"name":value'
* @access private
*/
function name_value($name, $value)
{
$encoded_value = $this->encode($value);
if (Services_JSON::isError($encoded_value)) {
return $encoded_value;
}
return $this->encode(strval($name)) . ':' . $encoded_value;
}
示例3: name_value
function name_value($name, $value)
{
$encoded_value = $this->_encode($value);
if (Services_JSON::isError($encoded_value)) {
return $encoded_value;
}
$lv = strval($name);
// do not escape keyvalues if they are just text, and not keywords...
if (preg_match('/^[a-z_]+$/i', $lv)) {
if (!in_array($lv, $GLOBALS['Pman_Builder_Generator_JSON']['keywords'])) {
return $lv . ' : ' . $encoded_value;
}
}
return $this->_encode(strval($name)) . ' : ' . $encoded_value;
}
示例4: test_to_JSON
function test_to_JSON()
{
$this->assertTrue(Services_JSON::isError($this->json->encode($this->res)), "resource case: {$this->res_d}");
$this->assertTrue(Services_JSON::isError($this->json->encode($this->arr)), "array case: {$this->arr_d}");
$this->assertTrue(Services_JSON::isError($this->json->encode($this->obj)), "object case: {$this->obj_d}");
}
示例5: name_value
/**
* array-walking function for use in generating JSON-formatted name-value pairs
*
* @param string $name name of key to use
* @param mixed $value reference to an array element to be encoded
*
* @return string JSON-formatted name-value pair, like '"name":value'
* @access private
*/
static function name_value($name, $value)
{
$encoded_value = self::encode($value);
if (Services_JSON::isError($encoded_value)) {
return $encoded_value;
}
return self::encode(strval($name)) . ':' . $encoded_value;
}
示例6: stdclass
/**
* Create a JSON-RPC client
*
* @param string $method A valid Mail API JSON-RPC method
* @param string $args Parameters for your method
* @return string | false If successful, a string is returned containing the JSON
* data decoded into a PHP array. If a curl or JSON encode/decode
* error occurs, the error is stored in $this->web_services_error. Note that
* access to the HTTP status code (for further error checking) is not provided
* in this method.
*/
function __call($method, $args)
{
$body = new stdclass();
$body->method = $method;
$body->params = $args;
// Use the JSON PHP extension if it's available
if (function_exists('json_encode')) {
// Anything json_encode can't encode is encoded as nulls
$data = json_encode($body);
} else {
$json = new Services_JSON();
$data = $json->encode($body);
if ($json->isError($data)) {
$this->web_services_error = "Error encoding JSON";
return false;
}
}
$ch = curl_init(self::jsonrpc_endpoint . "?appid={$this->appid}&WSSID={$this->WSSID}");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Cookie: {$this->cookie}"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$jsondata = curl_exec($ch);
if (curl_errno($ch)) {
$this->web_services_error = "Curl error number: " . curl_errno($ch);
return false;
}
curl_close($ch);
// Use the JSON PHP extension if it's available
if (function_exists('json_encode')) {
$data = json_decode($jsondata);
if ($data == null) {
$this->web_services_error = "Error decoding JSON";
return false;
}
} else {
$data = $json->decode($jsondata);
if ($json->isError($data)) {
$this->web_services_error = "Error decoding JSON";
return false;
}
}
return $data;
}