Created
December 2, 2012 06:07
-
-
Save shobhit/4187181 to your computer and use it in GitHub Desktop.
Read JSON from HTTP Json URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Json into a Python object | |
import urllib2 | |
import json | |
req = urllib2.Request("http://localhost/sensors/temperature.json") | |
opener = urllib2.build_opener() | |
f = opener.open(req) | |
json = json.loads(f.read()) | |
print json | |
print json['unit'] | |
# Array example | |
import urllib2 | |
import json | |
req = urllib2.Request("http://vimeo.com/api/v2/video/38356.json") | |
opener = urllib2.build_opener() | |
f = opener.open(req) | |
json = json.loads(f.read()) | |
print json | |
print json[0]['title'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment