PHP JSON文件解析并获取key、value,判断key是否存在
生活随笔
收集整理的這篇文章主要介紹了
PHP JSON文件解析并获取key、value,判断key是否存在
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
/******************************************************************************* PHP JSON文件解析并獲取key、value,判斷key是否存在* 說明:* 配置文件以JSON格式存放在文件中,key、value都是未知且要被處理的數(shù)據(jù)。** 2017-3-14 深圳 南山平山村 曾劍鋒*****************************************************************************/一、參考文檔:1. Getting JSON data with PHPhttp://stackoverflow.com/questions/16578019/getting-json-data-with-php2. 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這兩個函數(shù)對值為空的返回值是不一樣的。
?
轉(zhuǎn)載于:https://www.cnblogs.com/zengjfgit/p/6550157.html
總結(jié)
以上是生活随笔為你收集整理的PHP JSON文件解析并获取key、value,判断key是否存在的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flask-第二课:路由
- 下一篇: IIS7配置PHP 报错 对找不到的文件