2012-07-31 62 views
9
$a = '[{"function":"error_handler","class":"LP","type":"::","args":[256,"Call to undefined method LP_pdo::get_rorzxx() on D:\\MARK\\htdocs\\lessphptest\\application\\controllers\\users.php (23)","D:\\MARK\\htdocs\\lessphp\\LP.php",210,{"e":{"type":1,"message":"Call to undefined method LP_pdo::get_rorzxx()","file":"D:\\MARK\\htdocs\\lessphptest\\application\\controllers\\users.php","line":23}}]},{"file":"D:\\MARK\\htdocs\\lessphp\\LP.php","line":210,"function":"trigger_error","args":["Call to undefined method LP_pdo::get_rorzxx() on D:\\MARK\\htdocs\\lessphptest\\application\\controllers\\users.php (23)",256]},{"function":"shutdown","class":"LP","type":"::","args":[]}]'; 
$a = json_decode($a); 
print_r($a); 

echo json_last_error(); 

print_r()返回空白。json_decode()返回空白,但是它是有效的json

json_last_error()收益4是JSON_ERROR_SYNTAX

但是,當我在http://jsonlint.com/運行JSON字符串返回Valid JSON

任何想法,爲什麼?

+1

嘗試:$ B = array(); $ b = json_decode($ a,true);這應該將json轉換爲關聯數組,但是您首先需要聲明$ b = array(); – Onheiron 2012-07-31 11:07:08

回答

12

您需要再次逃脫你\一次PHP和一次JSON

D:\\\\....

+0

當然你的意思是逃避你的\ \而不是/ – 2012-07-31 11:06:37

+0

的工作,但有沒有這樣做的功能?我只是在記事本中找到/替換:-) – IMB 2012-07-31 11:18:01

+4

@IMB PHP也具有出色的查找/替換功能! '$ str = str_replace('\','\\',$ str);';-) – Kaii 2012-07-31 11:25:49

0

嘗試設置編碼爲UTF-8 ...做的工作對我來說