如何使用Python从json读取特定元素的值?

时间:2016-06-02 12:13:27

标签: python json

我有以下示例json文件,我想使用python获取ipAddress的值。

{
  "hostId" : "65cb096f-7adb-4197-0c61-b0a1a67236d4",
  "ipAddress" : "10.2.1.354",
  "hostname" : "localhost",
  "rackId" : "/default",
  "hostUrl" : "http://localhost:7180/cmf/hostRedirect/65cb096f-7adb-4197-0c61-b0a1a67236d4",
}

我可以在shellscript中使用grep工具来执行此操作但不确定如何在Python中执行此操作。在python中有没有像grep,awk或sed那样的特定工具?我的输出应为10.2.1.354

1 个答案:

答案 0 :(得分:1)

您可以使用:

{{1}}

希望它会有所帮助。