本文整理汇总了PHP中is_json函数的典型用法代码示例。如果您正苦于以下问题:PHP is_json函数的具体用法?PHP is_json怎么用?PHP is_json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_json函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeObjectParts
public static function writeObjectParts($obj)
{
////var_dump("writing obj: " . $obj["varname"]);
////var_dump($obj);
$adjObj = array();
foreach ($obj as $key => $value) {
$strkey = strval($key);
if (substr($strkey, 0, 1) == "/") {
$strkey = substr($strkey, 1);
}
$adjObj[$strkey] = $value;
}
$obj = $adjObj;
foreach ($obj as $key => $value) {
$strkey = strval($key);
if ($value == null) {
////var_dump("reading null: " . $obj["varname"] . "." . $strkey);
$value = PiPress::getVar($obj["varname"] . "." . $strkey);
}
if (is_string($value) && is_json($value)) {
////var_dump("json string");
$value = json_decode($value, true);
}
////var_dump("dump1: ");
////var_dump($value);
if (is_array($value)) {
$value["varname"] = $obj["varname"] . "." . $strkey;
//var_dump($value["varname"]);
PiPress::writeObjectParts($value);
$obj[$key] = null;
}
}
//PiPress::createDocumentation($obj);
file_put_contents("./" . $obj["varname"] . ".json", json_encode($obj));
}
示例2: __construct
function __construct()
{
parent::__construct();
if ($this->config->item('use_db_config')) {
// Get CI instance so we can set a global var.
$CI =& get_instance();
// First check memcache, if found use dbconfig from memcache
if ($cached = $this->memcache->get('dbconfig')) {
// Override data origin.
$cached->_data_origin = 'memcached';
$CI->dbconfig = $cached;
return true;
}
// Get config from db
$result = $this->db->select('key, value')->get('config')->result();
// Create new array and set data origin
$dbconf = array('_data_origin' => 'database');
// Loop through db-result.
foreach ($result as $conf) {
$dbconf[addslashes($conf->key)] = is_json($conf->value) ? json_decode($conf->value) : $conf->value;
}
// Cache in memcache forever
$this->memcache->set('dbconfig', (object) $dbconf, 0);
} else {
// Default to an empty array
$dbconf = array();
}
// Set dbconfig from database result.
$CI->dbconfig = (object) $dbconf;
}
示例3: getContentAttribute
/**
* Menu json to array.
*
* @param $content
* @return mixed
*/
public function getContentAttribute($content)
{
if (is_json($content)) {
return json_decode($content);
}
return $content;
}
示例4: Curl
function Curl($url, $method = 'GET', $postData = array())
{
$data = '';
if (!empty($url)) {
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if (is_json($postData)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
}
if (strtoupper($method) == 'POST') {
$curlPost = is_array($postData) ? http_build_query($postData) : $postData;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
}
$data = curl_exec($ch);
curl_close($ch);
} catch (Exception $e) {
$data = null;
}
}
return $data;
}
示例5: valueFromUrl
public static function valueFromUrl($_url)
{
$request_http = new com_http($_url);
$dataUrl = $request_http->exec();
if (!is_json($dataUrl)) {
return;
}
return json_decode($dataUrl, true);
}
示例6: categorization
function categorization($id = null)
{
header('Content-Type: application/json');
$cat = $this->categorization_model->get_categorization($id);
$cat_settings = array_get_value((array) $cat, 'cat_settings');
$cat_settings = unserialize($cat_settings);
$cat_settings = $cat_settings && is_json($cat_settings) ? $cat_settings : json_encode(array('url' => base_url('data/category-builder-template.js')), JSON_UNESCAPED_SLASHES);
echo $cat_settings;
}
示例7: decode
/**
* Decode a request result.
*
* @param $body
* @return mixed
*/
private function decode($body)
{
if (is_json($body)) {
return json_decode($body, true);
}
if (is_xml($body)) {
return xml_to_json($body);
}
return $body;
}
示例8: doImport
public function doImport()
{
$jsonData = file_get_contents($this->importFile);
if (is_json($jsonData) === false) {
throw new Exception('El fichero de importación no parece que este en formato json');
}
$arrayData = Zend_Json::decode($jsonData, Zend_Json::TYPE_ARRAY);
foreach ($arrayData as $roleData) {
$this->createRole($roleData);
}
}
示例9: parse
public function parse()
{
$data = $this->data;
if (is_array($data)) {
return $this->arrayParser($data);
}
if (is_json($data)) {
return $this->jsonParser($data);
}
return $this->arrayParser($data);
}
示例10: get_api_data
function get_api_data($url, $param = array())
{
$url = API_URL . $url;
$sign = encrypt($param);
$param['sign'] = $sign;
$api_str = send_request($url, $param);
if (is_json($api_str)) {
return json_decode($api_str, TRUE);
} else {
return return_format(array($api_str), "json_str 解析错误,这是api内部报错!请联系1162097842@qq.com", API_NORMAL_ERR);
}
}
示例11: sendData
private function sendData($param)
{
$url = C('WEB_URL');
$checkCode = C('CHECK_CODE');
$param = json_encode($param);
$post = array('param' => $param, 'sign' => md5($param . $checkCode));
$data = url_data($url, $post);
if (is_json($data)) {
$data = json_decode($data, true);
}
return $data;
}
示例12: testIsJson
public function testIsJson()
{
$this->assertEquals(is_json('[]'), true);
$this->assertEquals(is_json('[1]'), true);
$this->assertEquals(is_json('[1.23]'), true);
$this->assertEquals(is_json('["a"]'), true);
$this->assertEquals(is_json('["a",1]'), true);
$this->assertEquals(is_json('[1,"a",["b"]]'), true);
$this->assertEquals(is_json('x'), false);
$this->assertEquals(is_json('['), false);
$this->assertEquals(is_json('[]]'), false);
$this->assertEquals(is_json('[[]'), false);
$this->assertEquals(is_json('["a"'), false);
}
示例13: debug
public function debug($method = 'config')
{
if (method_exists(__CLASS__, $method)) {
$result = self::$method(Input::all());
if (is_array($result)) {
Helper::ta($result);
} elseif (is_json($result)) {
Helper::ta(json_decode($result, TRUE));
} elseif (is_string($result)) {
echo $result;
}
} else {
echo 'Error...';
}
}
示例14: requestKeyValue
public function requestKeyValue($url, $method = 'GET', $fields = [])
{
try {
$response = $this->request($url, $method, $fields);
} catch (Exception $e) {
throw $e;
}
// Extract body from response.
$body = $response->getBody();
// Handle expected json.
$data = [];
if (is_json($body, $data)) {
return $data;
}
// Parse body as keyvalue.
return keyvalue_to_array($body);
}
示例15: getVerifyToken
public function getVerifyToken($id)
{
global $table_prefix;
$id = intval($id);
if (!$this->isExistID($id)) {
return FALSE;
}
try {
$sth = $this->dbh->prepare("SELECT * FROM {$table_prefix}users_temp WHERE `id` = :id ");
$sth->bindParam(':id', $id);
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
$verify_token = $result['verify_token'];
if (is_json($verify_token)) {
$verify_token = json_decode($verify_token, true);
} else {
$verify_token = array("", "");
}
return $verify_token;
} catch (PDOExecption $e) {
echo "<br>Error: " . $e->getMessage();
}
}