【发布时间】:2014-04-17 13:32:01
【问题描述】:
我需要在下面的字典列表中搜索键 name,并且需要为该特定字典获取 uuid 的值
body = '''{
"operatingsystems":[
{
"uuid":"2baae445-eec5-41c4-a373-05f0125d4dc0",
"name":"my node",
"description":"my node is compute node",
"status":"",
"provision_capabilities":[
"controller"
],
"hostname":"9.37.75.49",
"os_name":"Linux",
"os_type":"RHEL",
"version":"6.5",
"architecture":"x86_64",
"is_hypervisor":"false",
"hypervisor_type":null,
"hypervisor_id":null,
"total_memory":16334340,
"processor_speed":null,
"processor_num_cores":null,
"max_storage":"",
"links":[
{
"href":"/v1/5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/2baae445-eec5-41c4-a373-05f0125d4dc0",
"rel":"self"
},
{
"href":"5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/2baae445-eec5-41c4-a373-05f0125d4dc0",
"rel":"bookmark"
}
],
"created":"2014-04-16T05:44:04.327626",
"updated":"2014-04-16T06:45:58.181892"
},
{
"uuid":"0fcc39c1-1956-41b9-97c8-8462edbb8a46",
"name":"OpsMgmt node3",
"description":"Operating system for pool3",
"status":"",
"provision_capabilities":[
"sdnve_controller"
],
"hostname":"9.37.75.121",
"os_name":"Linux",
"os_type":"RHEL",
"version":"6.5",
"architecture":"x86_64",
"is_hypervisor":false,
"hypervisor_type":null,
"hypervisor_id":null,
"total_memory":3923764,
"processor_speed":null,
"processor_num_cores":null,
"max_storage":"",
"links":[
{
"href":"/v1/5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/0fcc39c1-1956-41b9-97c8-8462edbb8a46",
"rel":"self"
},
{
"href":"5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/0fcc39c1-1956-41b9-97c8-8462edbb8a46",
"rel":"bookmark"
}
],
"created":"2014-04-16T05:44:04.452042",
"updated":null
},
{
"uuid":"1d15250f-ec0b-42e9-9e61-4da92024e024",
"name":"OpsMgmt node",
"description":"Operating system for pool",
"status":"",
"provision_capabilities":[
"compute"
],
"hostname":"9.37.88.253",
"os_name":"Linux",
"os_type":"RHEL",
"version":"6.5",
"architecture":"x86_64",
"is_hypervisor":false,
"hypervisor_type":null,
"hypervisor_id":null,
"total_memory":8030692,
"processor_speed":null,
"processor_num_cores":null,
"max_storage":"",
"links":[
{
"href":"/v1/5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/1d15250f-ec0b-42e9-9e61-4da92024e024",
"rel":"self"
},
{
"href":"5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/1d15250f-ec0b-42e9-9e61-4da92024e024",
"rel":"bookmark"
}
],
"created":"2014-04-16T06:22:36.261333",
"updated":null
},
{
"uuid":"315efdbd-9537-4b32-8675-63cff8b2f9b2",
"name":"OpsMgmt node itself",
"description":"Operating system for pool which is same as opsmanagement",
"status":"",
"provision_capabilities":[
"connectivity"
],
"hostname":"9.37.75.129",
"os_name":"Linux",
"os_type":"RHEL",
"version":"6.5",
"architecture":"x86_64",
"is_hypervisor":false,
"hypervisor_type":null,
"hypervisor_id":null,
"total_memory":65977136,
"processor_speed":null,
"processor_num_cores":null,
"max_storage":"",
"links":[
{
"href":"/v1/5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/315efdbd-9537-4b32-8675-63cff8b2f9b2",
"rel":"self"
},
{
"href":"5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/315efdbd-9537-4b32-8675-63cff8b2f9b2",
"rel":"bookmark"
}
],
"created":"2014-04-16T07:11:56.258874",
"updated":null
},
{
"uuid":"5c907a69-0ad0-4a81-b64b-6c2b281004d6",
"name":"compute node",
"description":"Operating system for Compute",
"status":"",
"provision_capabilities":[
"compute"
],
"hostname":"9.37.89.12",
"os_name":"Linux",
"os_type":"RHEL",
"version":"6.5",
"architecture":"x86_64",
"is_hypervisor":false,
"hypervisor_type":null,
"hypervisor_id":null,
"total_memory":32850352,
"processor_speed":null,
"processor_num_cores":null,
"max_storage":"",
"links":[
{
"href":"/v1/5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/5c907a69-0ad0-4a81-b64b-6c2b281004d6",
"rel":"self"
},
{
"href":"5e9dc1e2a6864739b278f0b67e6229c6/operatingsystems/5c907a69-0ad0-4a81-b64b-6c2b281004d6",
"rel":"bookmark"
}
],
"created":"2014-04-17T09:08:17.967685",
"updated":null
}
]
}'''
【问题讨论】:
-
向我们展示您的尝试。我们帮助解决错误.. 不做你的工作
-
这个问题似乎是题外话,因为它是一个家庭作业转储类型的问题。
-
@ErikAllik 这太苛刻了,还不错。
-
@ErikAllik:它可能缺少一点努力,但它也不是一个家庭垃圾场。
-
@ErikAllik:很可能是因为他们一开始就不知道它是 JSON?一旦你知道了所有这些事情就会很容易,当你还在开始的时候你会忘记它是什么样的。
标签: python json dictionary