python提取json字符串的值

 1 json_str={
 2     "actor":"邓超",
 3     "age":35,
 4     "book":[
 5         "英语",
 6         "数学",
 7         "美术"
 8     ],
 9     "children":[
10         {
11             "name":"等等",
12             "age":7,
13             "sex":"male"
14         },
15         {
16             "name":"花花",
17             "age":3,
18             "sex":"female"
19         }
20     ]
21 }
22 
23 
24 
25 #获取actor 的值
26 actor=json_str['actor']
27 #获取 book 的第二个值
28 book_2=json_str['book'][1]
29 #获取第二个孩子的性别
30 sex2=json_str['children'][1]['sex']

 

posted on 2020-06-09 16:52  小金鱼的笔记  阅读(4899)  评论(0)    收藏  举报