我打電話的網址:使用的urllib2和解碼使用JSON模塊JSON字符串解碼錯誤
url = "http://code.google.com/feeds/issues/p/chromium/issues/full/291?alt=json"
request = urllib2.Request(query)
response = urllib2.urlopen(request)
issue_report = json.loads(response.read())
我碰到下面的錯誤
http://code.google.com/feeds/issues/p/chromium/issues/full/291?alt=json
:
ValueError: Invalid control character at: line 1 column 1120 (char 1120)
我試圖檢查標題,我得到以下內容:
Content-Type: application/json; charset=UTF-8
Access-Control-Allow-Origin: *
Expires: Sun, 03 Jul 2011 17:38:38 GMT
Date: Sun, 03 Jul 2011 17:38:38 GMT
Cache-Control: private, max-age=0, must-revalidate, no-transform
Vary: Accept, X-GData-Authorization, GData-Version
GData-Version: 1.0
ETag: W/"CUEGQX47eCl7ImA9WxJaFEw."
Last-Modified: Tue, 04 Aug 2009 19:20:20 GMT
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Connection: close
我還嘗試添加的編碼參數如下:
issue_report = json.loads(response.read() , encoding = 'UTF-8')
我仍然會碰到同樣的錯誤。
看起來,你得到了什麼不是有效的json編碼的字符串。 – hakre
太好了,謝謝!我會照辦的。 – Dexter