当前位置: 首页>>代码示例>>PHP>>正文


PHP is_json函数代码示例

本文整理汇总了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));
 }
开发者ID:saurabhsrb,项目名称:pipress,代码行数:35,代码来源:piBeta.php

示例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;
 }
开发者ID:johusman,项目名称:internal,代码行数:30,代码来源:dbconfig.php

示例3: getContentAttribute

 /**
  * Menu json to array.
  *
  * @param $content
  * @return mixed
  */
 public function getContentAttribute($content)
 {
     if (is_json($content)) {
         return json_decode($content);
     }
     return $content;
 }
开发者ID:chictem,项目名称:chictem,代码行数:13,代码来源:Menu.php

示例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;
}
开发者ID:sanshilei,项目名称:password,代码行数:27,代码来源:pass.php

示例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);
 }
开发者ID:jeedom,项目名称:plugin-ecowatt,代码行数:9,代码来源:ecowatt.class.php

示例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;
 }
开发者ID:benznext,项目名称:CIDashboard,代码行数:9,代码来源:api.php

示例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;
 }
开发者ID:wsorprendente,项目名称:zipcode,代码行数:16,代码来源:Http.php

示例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);
     }
 }
开发者ID:jv10,项目名称:pimpon,代码行数:11,代码来源:Import.php

示例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);
 }
开发者ID:eskrano,项目名称:formbuilder,代码行数:11,代码来源:SelectParser.php

示例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);
    }
}
开发者ID:codekissyoung,项目名称:filmfest,代码行数:12,代码来源:functions.php

示例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;
 }
开发者ID:dalinhuang,项目名称:edu_hipi,代码行数:12,代码来源:SyncLogic.class.php

示例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);
 }
开发者ID:martinlindhe,项目名称:core_dev,代码行数:14,代码来源:htmlTest.php

示例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...';
     }
 }
开发者ID:Grapheme,项目名称:lipton,代码行数:15,代码来源:api.controller.php

示例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);
 }
开发者ID:furey,项目名称:laravel-facebook-service,代码行数:17,代码来源:FacebookRemote.php

示例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();
     }
 }
开发者ID:sujinw,项目名称:zjut_passport,代码行数:23,代码来源:class.zusertemp.php


注:本文中的is_json函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。