处理json文件python [英] Manipulating json files python
问题描述
我正在接收包含很多信息的JSON文件,并且我试图获取该JSON文件的某些属性,我在Python API上进行了研究,但找不到关于某些函数的任何信息,这些函数可以在JSON文件或使用"loads"方法加载的字符串,有人知道通过一种简单而干净的操作来获取指定信息的方法吗?
I'm receiving a JSON file with a lot of information, and I'm trying to get some properties of this JSON file, I research at Python API and I couldn't find any information about some function that search at the JSON file or the strings that's loaded with the "loads" method, someone knows some way to get the specified information by a simple and clean operation?
编辑
执行加载功能后,请遵循JSON文件:
Follow the JSON file after executed the loads function:
{
"servers": [
{
"status": "ACTIVE",
"updated": "2012-01-02T20:46:21Z",
"hostId": "ID",
"user_id": "ID",
"name": "Serve",
"links": [
{
"href": "URL",
"rel": "self"
},
{
"href": "URL",
"rel": "bookmark"
}
],
"addresses": {
"nuvemcpca": [
{
"version": 4,
"addr": "10.0.0.2"
}
]
},
"tenant_id": "nuvemcpca",
"image": {
"id": "15",
"links": [
{
"href": "URL",
"rel": "bookmark"
}
]
},
"created": "2012-01-02T20:19:04Z",
"uuid": "1710c4bb-3d48-49f9-b88e-2a19355de199",
"accessIPv4": "",
"accessIPv6": "",
"key_name": "name",
"progress": 100,
"flavor": {
"id": "1",
"links": [
{
"href": "URL",
"rel": "bookmark"
}
]
},
"config_drive": "",
"id": 15,
"metadata": {
}
}
我想获取状态信息.
推荐答案
您的数据似乎格式不正确,尤其是我看不到"servers":
后面的一个开口的右方括号在哪里,但我想说的是您要寻找的是:
Your data doesn't seem to be properly formatted, in particular I don't see where's the closing square bracket for the one opening just after "servers":
, but I'd say that what you're looking for is:
data['servers'][0]['status']
其中data
是指向json.loads
的结果的变量.
where data
is the variable that points to the result of json.loads
.
这篇关于处理json文件python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!