felix felix - 1 year ago 47
JSON Question

Get value for only one JSON variable

I want to get the value for

with Python, using
. I have this:

import requests
import json

res = requests.get('https://www.bitstamp.net/api/v2/ticker/btcusd/')
print res.json['last']

But it showed me this:

TypeError: 'instancemethod' object has no attribute '__getitem__'

It's working to get all JSON code with
but I want only the value from

Answer Source

res.json() will parse the responses json object, which you need to do, to access any value of it. So to access the value last, you need to do: res.json()['last']