json parse error in ruby - unexpected token at

Posted by RahTha on Stack Overflow See other posts from Stack Overflow or by RahTha
Published on 2010-02-26T09:14:43Z Indexed on 2010/05/08 19:08 UTC
Read the original article Hit count: 438

Filed under:
|
|

Hi,

I get errors at a lot of places when trying to retrieve ticker symbols for US companies from http://d.yimg.com/autoc.finance.yahoo.com/autoc?callback=YAHOO.Finance.SymbolSuggest.ssCallback&query=Wal-Mart

I have tried to:

resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
qwe = data.split("symbol")
p qwe[1]
arr1 = data.split("(")
arr2 = arr1[1].split(")")
fnl = arr2[0].gsub(/-/, '')
fnl = fnl.gsub(/\(/, '')
fnl = fnl.gsub(/\)/, '')
fnl = fnl.gsub(/\./, '')
fnl = fnl.gsub('\'', '"')
fnl = fnl.gsub(/([\{|\,}])\s*([a-zA-Z]+):/, '\1 "\2":')

But this doesnt help as i see:

/Library/Ruby/Gems/1.8/gems/json-1.2.0/lib/json/common.rb:123:in `parse': 353: unexpected token at '{"symbol":"BEEV","name": "BENCHMARK ENERGY CORP ' (JSON::ParserError)

Any clues as to what i might be doing wrong?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about JSON