2016-06-06 82 views
1

我有一個JSON字符串。PHP檢查JSON以查看它是否處於掛起狀態和/或未掛起

  • 我想呼應「待定」如果狀態掛起,
  • 我想回聲「活躍」如果狀態處於活動狀態,
  • 我想回聲「無效的」,如果無效。

的Json

待定:

"{"result":"success","message":"License key details retrieved.","status":"pending","max_allowed_domains":"1","email":"","registered_domains":[],"date_created":"","date_renewed":"","date_expiry":""}" 

活動:

"{"result":"success","message":"License key details retrieved.","status":"active","max_allowed_domains":"1","email":"","registered_domains":[],"date_created":"","date_renewed":"","date_expiry":""}" 

無效:

"{"result":"error","message":"Invalid license key"}" 

謝謝!

+1

所以解碼JSON到本地的PHP結構,然後訪問該結構的/測試件等使用任何其他結構。 –

+0

你累了什麼?我們幫助解決問題不會給你答案... – nerdlyist

回答

0

如果您使用PHP,請在包含JSON字符串的變量上使用json_decode()開始。

之後,你應該能夠檢查你的數組中的值。

鬆散例如:

$arr = json_decode($json_string); 

if($arr['result'] == "error"){ 
    echo "Invalid"; 
}elseif($arr['result'] == "success" && $arr['status'] == "pending"){ 
    echo "Pending"; 
}elseif($arr['result'] == "success" && $arr['status'] == "active"){ 
    echo "Active"; 
}else{ 
    echo "what if it's something else??"; 
}