我有以下的JSON字符串從節點JS服務回來:在PHP中解析JSON的正確方法是什麼?
"{\"success\":true,\"isavailable\":true}"
當我嘗試使用在PHP我坐上的var_dump以下json_decode():
string '{"success":true,"isavailable":true}' (length=35)
所以,我開始着手做到以下幾點:
$str = str_replace("\"{", "'{", $str);
$str = str_replace("}\"", "}'", $str);
$str = str_replace('\"','"',$str);
當我做到這一點我從返回語法錯誤上次錯誤和NULL值。
那麼,在PHP中解析這個JSON字符串的正確方法是什麼?
'json_decode'適用於我:http://codepad.org/LIBC8ihP – 2012-07-05 19:00:29
'json_decode'僅在PHP 5.2.0 +中可用? – AlexLittlejohn 2012-07-05 19:03:43
@AlexLittlejohn爲什麼你會使用5.2.0以上的版本? – Lusitanian 2012-07-05 19:07:19