zoukankan      html  css  js  c++  java
  • PHP JSON文件解析并获取key、value,判断key是否存在

    /******************************************************************************
     *             PHP JSON文件解析并获取key、value,判断key是否存在
     * 说明:
     *     配置文件以JSON格式存放在文件中,key、value都是未知且要被处理的数据。
     *
     *                                         2017-3-14 深圳 南山平山村 曾剑锋
     *****************************************************************************/
    
    一、参考文档:
        1. Getting JSON data with PHP
            http://stackoverflow.com/questions/16578019/getting-json-data-with-php
        2. how to know whether key exists in Json string [duplicate]
            http://stackoverflow.com/questions/10176293/how-to-know-whether-key-exists-in-json-string   
    
    二、操作方法
        1. 获取json的key、value:
            $string  = file_get_contents("jsonFile.json");
            $json_array = json_decode($string,true);
    
            foreach ($json_array as $key => $value){
    
                $store = $key -> store;
                $general_cat = $key -> general_cat;
                $spec_cat = $key -> spec_cat;
    
                if (!is_null($key -> mainImg_select)){
                    $cat = $key -> cat;
                }
    
                echo $headURL;
            }
        2. 判断key是存在的,并且非空:
            1. 处理方法:
                if( isset( $mydata['user_id'] ) ){
                   // do something
                }
            2. array_key_exists、isset这两个函数对值为空的返回值是不一样的。
  • 相关阅读:
    test example
    SSD: ReLU6
    jupyter
    ubuntu+anaconda
    linux动态库
    ssd制作数据和训练
    ncnn框架
    Lock->ReentrantLock->ReentrantReadWriteLock简介
    Synchronized简介与原理
    ThreadLocal简介与原理
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/6550157.html
Copyright © 2011-2022 走看看