可能重複:
How to check if an array element exists?怎麼知道的JSON字符串是否存在關鍵
道歉,如果我錯了,我是新來的PHP,有什麼辦法找出是否密鑰存在於使用json_decode
函數進行解碼後的Json
字符串中。
$json = {"user_id":"51","password":"abc123fo"};
簡介:
$json = {"password":"abc123fo"};
$mydata = json_decode($json,true);
user_id = $mydata['user_id'];
如果JSON字符串不是由USER_ID的,它拋出像Undefined index user_id
一個異常,那麼有沒有什麼辦法來檢查JSON字符串是否存在的關鍵,請幫幫我,我正在使用PHP 5.3 and Codeigniter 2.1 MVC
在此先感謝
閱讀文檔可能會有幫助:http://www.php.net/manual/en/function.array-key-exists.php – 2012-04-16 14:44:56