0
爲什麼我不能json_decode數組?爲什麼我不能json_decode數組?
代碼波紋管有「\ w」,當我使用json_decode時,php返回null值,爲什麼?我該如何解決它?
<?php
$str='[0,"^(\w)+$","Your email is unvailable"]';
$arr= json_decode($str,true);
var_dump($arr); // null
爲什麼我不能json_decode數組?爲什麼我不能json_decode數組?
代碼波紋管有「\ w」,當我使用json_decode時,php返回null值,爲什麼?我該如何解決它?
<?php
$str='[0,"^(\w)+$","Your email is unvailable"]';
$arr= json_decode($str,true);
var_dump($arr); // null
在JSON中的字符串中,反斜槓必須被轉義;你想(demo)
$str = '[0,"^(\\\\w)+$","Your email is unvailable"]';
我們需要有四個反斜槓因爲PHP字符串文字需要反斜槓轉義爲好。
逃生逃生逃脫''''''。瘋狂。 :) –
一個數組是一個解碼的json,最重要的是,這不是一個數組。 –
您是否嘗試在正則表達式中使用雙斜槓? – Andrew
我的意思是json_decode認爲你的\ w作爲不合法的轉義編碼字符。 – Andrew