tags:

views:

37

answers:

1

Hi, i have to build an small app in order to show some data from the Google Financial API. I know that i could study it inside out, but I don't have much time. The url http://www.google.com/finance/info?q=MSFT returns this JSON string:

// [ { "id": "358464" ,"t" : "MSFT" ,"e" : "NASDAQ" ,"l" : "24.38" ,"l_cur" : "24.38" ,"ltt":"4:00PM EDT" ,"lt" : "Oct 1, 4:00PM EDT" ,"c" : "-0.11" ,"cp" : "-0.45" ,"ccol" : "chr" ,"el": "24.39" ,"el_cur": "24.39" ,"elt" : "Oct 1, 7:58PM EDT" ,"ec" : "+0.01" ,"ecp" : "0.04" ,"eccol" : "chg" ,"div" : "0.16" ,"yld" : "2.63" } ]

I don't know how to make that string available to a view. I need to "catch it" and show (some of) it in my template. I need something like:

def myview(...)
    URL = 'http://www.google.com/finance/info?q=MSFT'
    mystring = catchfromURL(URL)

    #work with the string

    return render_to_response('page.html', mystring)

Thanks in advance.

+2  A: 

That little // at the beginning threw me off too. Here's what you do:

import json
jsonData = json.loads(mystring[3:])

Now, I don't know what any of the encoded data there means, but that's how you can get it as python objects.

TokenMacGuy
I could only say: Awesome!
Pablo