How to work with JSON string returned by remote URL (with Django)?

I need to create a small application to show some data from the Google Financial API. I know that I can study it inside out, but I have little 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 do not know how to make this line available for presentation. I need to “catch” it and show (some) 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.

+3
source share
1 answer

This little one //also threw me off at the beginning. Here is what you do:

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

, , python.

+6

Source: https://habr.com/ru/post/1767638/


All Articles