Last active
December 17, 2015 13:49
-
-
Save fmasanori/5620404 to your computer and use it in GitHub Desktop.
json object_hook
This file contains hidden or 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
import urllib.request | |
import json | |
from pprint import pprint | |
class Dic42(dict): | |
def __missing__(self, key): | |
return '42' | |
url = 'https://graph.facebook.com/fmasanori' | |
resp = urllib.request.urlopen(url).read() | |
data = json.loads(resp.decode('utf-8'), | |
object_hook = Dic42) | |
pprint (data) | |
print () | |
print ('Ultimate answer:', data['Ultimate answer']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment