Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update the advanced doc to use the r.json method

  • Loading branch information...
commit 7687746c7c1691946f24e414c065025f895104e6 1 parent 5d87e1a
Thomas Grainger authored January 04, 2013

Showing 1 changed file with 5 additions and 10 deletions. Show diff stats Hide diff stats

  1. 15  docs/user/advanced.rst
15  docs/user/advanced.rst
Source Rendered
@@ -313,17 +313,12 @@ out what type of content it is. Do this like so::
313 313
     ...
314 314
     application/json; charset=utf-8
315 315
 
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.
322 318
 
323 319
 ::
324 320
 
325  
-    >>> import json
326  
-    >>> commit_data = json.loads(r.text)
  321
+    >>> commit_data = r.json()
327 322
     >>> print commit_data.keys()
328 323
     [u'committer', u'author', u'url', u'tree', u'sha', u'parents', u'message']
329 324
     >>> print commit_data[u'committer']
@@ -380,7 +375,7 @@ Cool, we have three comments. Let's take a look at the last of them.
380 375
     >>> r = requests.get(r.url + u'/comments')
381 376
     >>> r.status_code
382 377
     200
383  
-    >>> comments = json.loads(r.text)
  378
+    >>> comments = r.json()
384 379
     >>> print comments[0].keys()
385 380
     [u'body', u'url', u'created_at', u'updated_at', u'user', u'id']
386 381
     >>> print comments[2][u'body']
@@ -417,7 +412,7 @@ the very common Basic Auth.
417 412
     >>> r = requests.post(url=url, data=body, auth=auth)
418 413
     >>> r.status_code
419 414
     201
420  
-    >>> content = json.loads(r.text)
  415
+    >>> content = r.json()
421 416
     >>> print content[u'body']
422 417
     Sounds great! I'll get right on it.
423 418
 

0 notes on commit 7687746

Please sign in to comment.
Something went wrong with that request. Please try again.