Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jgwill
Forked from sirleech/gist:2660189
Last active December 11, 2018 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgwill/bf776205d7ff15fcc283ee8208c4e398 to your computer and use it in GitHub Desktop.
Save jgwill/bf776205d7ff15fcc283ee8208c4e398 to your computer and use it in GitHub Desktop.
Python Read JSON from HTTP Request of URL
#
import urllib.request, json
with urllib.request.urlopen('http://afc:88/api/search/tag/resolving') as url:
data = json.loads(url.read().decode())
#print(data)
#Printing the Id of the first result
i=data['searchresults']
print(i[0]['Id'])
print(i[0]['ChatLine'])
# Load Json into a Python object
import urllib2
import json
req = urllib2.Request("http://localhost:81/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