2016-12-26 40 views
0

其實,我是新來的JSON-python和我得到simplejson.scanner.jsondecodeerror的錯誤:期待值期待值:第1行1列(字符0),我試圖爲[「系列「] [」TimeStamp「]數據JSONDecodeError使用JSON數據

import urllib 
import simplejson 
response = urllib.urlopen("http://chartapi.finance.yahoo.com/instrument/1.0/RUSHIL.NS/chartdata;type=quote;range=5d/json") 
#response.read() //this works 
data = simplejson.loads(response) 
print data //error 

回答

1

我發現你的數據有一些不必要的詞。響應在數據的第一個數據處有'finance_charts_json_callback('。所以你應該刪除這個函數字符串。以下代碼顯示。

import urllib 
import simplejson 
response = urllib.urlopen("http://chartapi.finance.yahoo.com/instrument/1.0/RUSHIL.NS/chartdata;type=quote;range=5d/json") 
a = response.read() 
a = a[29:-1] # remove function wrap 
data = simplejson.loads(a) 
print(data) 
+0

謝謝,我沒有注意到 –