File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed
Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,6 @@ The `json <https://docs.python.org/2/library/json.html>`_ library can parse JSON
66Parsing JSON
77------------
88
9- The json libary is imported like this:
10-
11- .. code-block :: python
12-
13- import json
14-
159Take the following string containing JSON data:
1610
1711.. code-block :: python
@@ -22,26 +16,28 @@ It can be parsed like this:
2216
2317.. code-block :: python
2418
25- converted_dict = json.loads(json_string)
19+ import json
20+ parsed_json = json.loads(json_string)
2621
2722 and can now be used as a normal dictionary:
2823
2924.. code-block :: python
3025
31- print (converted_dict [' first_name' ])
26+ print (parsed_json [' first_name' ])
3227 " Guido"
3328
34- You can also convert a dictionary to JSON:
29+ You can also convert a the following to JSON:
3530
3631.. code-block :: python
3732
3833 d = {
3934 ' first_name' : ' Guido' ,
40- ' second_name' : ' Rossum'
35+ ' second_name' : ' Rossum' ,
36+ ' titles' : [' BDFL' , ' Developer' ],
4137 }
4238
4339 print (json.dumps(d))
44- " {' first_name':' Guido',' last_name':' Rossum'} "
40+ ' {" first_name": " Guido", " last_name": " Rossum", "titles": ["BDFL", "Developer"]} '
4541
4642
4743 simplejson
You can’t perform that action at this time.
0 commit comments