@@ -313,17 +313,12 @@ out what type of content it is. Do this like so::
313313 ...
314314 application/json; charset=utf-8
315315
316- So, GitHub returns JSON. That's great, we can use the JSON module to turn it
317- into Python objects. Because GitHub returned UTF-8, we should use the
318- ``r.text `` method, not the ``r.content `` method. ``r.content `` returns a
319- bytestring, while ``r.text `` returns a Unicode-encoded string. I have no plans
320- to perform byte-manipulation on this response, so I want any Unicode code
321- points encoded.
316+ So, GitHub returns JSON. That's great, we can use the ``r.json `` method to
317+ parse it into Python objects.
322318
323319::
324320
325- >>> import json
326- >>> commit_data = json.loads(r.text)
321+ >>> commit_data = r.json()
327322 >>> print commit_data.keys()
328323 [u'committer', u'author', u'url', u'tree', u'sha', u'parents', u'message']
329324 >>> print commit_data[u'committer']
@@ -380,7 +375,7 @@ Cool, we have three comments. Let's take a look at the last of them.
380375 >>> r = requests.get(r.url + u'/comments')
381376 >>> r.status_code
382377 200
383- >>> comments = json.loads(r.text )
378+ >>> comments = r.json( )
384379 >>> print comments[0].keys()
385380 [u'body', u'url', u'created_at', u'updated_at', u'user', u'id']
386381 >>> print comments[2][u'body']
@@ -417,7 +412,7 @@ the very common Basic Auth.
417412 >>> r = requests.post(url=url, data=body, auth=auth)
418413 >>> r.status_code
419414 201
420- >>> content = json.loads(r.text )
415+ >>> content = r.json( )
421416 >>> print content[u'body']
422417 Sounds great! I'll get right on it.
423418
0 commit comments