如何从json中提取数据。这里的其他答案对我不起作用

时间:2017-02-06 10:02:20

标签: python json

我想在python中从这个json中提取Mac_Address。有人可以帮忙吗?

{"list":
    [{
       "Group_Devices_id":3,
       "User_Id":19,
       "Mac_Address":" fe80::f17a:4a64:7192:ed68%2 ",
       "Master_Device":"T"
    }],
    "success":true}

3 个答案:

答案 0 :(得分:0)

- Import json
- data = json.loads('{"list": [{ "Group_Devices_id":3, "User_Id":19,
   "Mac_Address":" fe80::f17a:4a64:7192:ed68%2 ", "Master_Device":"T"
   }], "success":true}')
- data['list'][0]['Mac_Address']

Desc : Import json libraray, then load your data. then access any elements.

答案 1 :(得分:0)

import json
data = json.loads('{"list": [{ "Group_Devices_id":3, "User_Id":19,
       "Mac_Address":" fe80::f17a:4a64:7192:ed68%2 ", "Master_Device":"T"
       }], "success":true}'

for item in data["list"]:
   print item["Mac_Address"]

1)加载数据

2)假设您需要从列表的大量数据中获取Mac_Address,    然后使用“for ... in ..”来处理

答案 2 :(得分:0)

以下是关于“如何解析json文件/字符串”的类似问题的答案: https://stackoverflow.com/a/42066196/4124672

阅读并询问您是否有任何疑问。