2012-01-12 38 views
1

我使用PHP內置函數json_encode()將對象數組轉換爲json string。然後我使用AJAX方法獲取xmlhttp.responseText。我使用document.write(xmlhttp.responseText)來檢查響應字符串。例如,該字符串是如下:JSON.parse語法錯誤,而JSONLint告訴我,json字符串有效

{"index":0,"marks":2} 

但是,當我使用JSON.parse()解析JSON字符串,我得到一個語法錯誤。所以,我把這個字符串複製到JSONLint來檢查它是否有效,結果是否定的。

Parse error on line 1: 
{ "index": 0 
^ 
Expecting '{', '[' 

但是當我手工輸入它時,它是有效的。爲什麼?

+0

這是它嗎? '「index」:0'或''index「:」0「'? – davogotland 2012-01-12 12:54:11

回答

相關問題