Closed thongly closed 12 years ago
What kind of error do you get?
2012/5/18 thongly < reply@reply.github.com
I'm relatively new to python, but I believe this may be due to UJSON not being able to escape certain parts of the Google Finance feed.
CJSON is able to decode this using cjson.decode.
Given the benchmarks, I would love to be able to use ujson for this
Reply to this email directly or view it on GitHub: https://github.com/esnme/ultrajson/issues/44
Jonas Tärnström Product Manager • e-mail: jonas.tarnstrom@esn.me • skype: full name "Jonas Tärnström" • phone: +46 (0)734 231 552
ESN Social Software AB www.esn.me
The data at that URL starts with "\n//", which is not valid JSON. Remove that and it will work.
>>> import ujson, urllib2
>>> json = urllib2.urlopen("http://www.google.com/finance/info?infotype=infoquoteall&q=CI:NYSE,CINF:Nasdaq,CTAS:Nasdaq,CSCO:Nasdaq,C:NYSE,CTXS:Nasdaq,CLF:NYSE,CLX:NYSE,KO:NYSE,CCE:NYSE,CTSH:Nasdaq,CL:NYSE,CMCSA:Nasdaq,CMA:NYSE,CSC:NYSE,CAG:NYSE").read()
>>> json[:5]
'\n// ['
>>> ujson.decode(json)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Expected object or value
>>> ujson.decode(json[3:])
[{u'el': u'43.68', u'eo': u'', u'eccol': u'chg', u'ec': u'+0.25', u'vo': u'0.00', u'eps': u'4.57', u'inst_own': u'87%', u'cp': u'
Even when I look up the " [ " with .find and limit my decode with that, I still get an error.
Traceback (most recent call last):
File "<pyshell#32>", line 1, in
And what does repr(info[z:y]) give you?
Specifically, when I try what @mthurlin suggested:
jsonob = json.decode(info[5:])
Traceback (most recent call last):
File "<pyshell#33>", line 1, in
You are removing the first [
. If you look at my example, I did only remove the first three chars.
I get the same thing when I run it with [3:]
jsonobj = json.decode(info[3:])
Traceback (most recent call last):
File "<pyshell#34>", line 1, in
URL: 'http://www.google.com/finance/info?infotype=infoquoteall&q=CI:NYSE,CINF:Nasdaq,CTAS:Nasdaq,CSCO:Nasdaq,C:NYSE,CTXS:Nasdaq,CLF:NYSE,CLX:NYSE,KO:NYSE,CCE:NYSE,CTSH:Nasdaq,CL:NYSE,CMCSA:Nasdaq,CMA:NYSE,CSC:NYSE,CAG:NYSE'
I'm relatively new to python, but I believe this may be due to UJSON not being able to escape certain parts of the Google Finance feed.
CJSON is able to decode this using cjson.decode.
Given the benchmarks, I would love to be able to use ujson for this