如何从json列表数据中获取特定索引

克罗克1516

我们有哪些我试图解析,而通过读数据的JSON数据urljsonresquest

示例杰森数据:

{ "statusMessage": "OK", "statusCode": 200, "response": { "id": "15015", "name": "cDOT_stx7116_esx01_07-18-2021_18.00.00.0586", "startTime": 1626624000472, "mounted": false, "vmwareSnapshot": "Yes", "status": "Completed", "policy": "SCV_DLY_NoDR", "entities": [ { "entityName": "CISCAT-2016_CN-SKK", "quiesced": true, "uuid": "500334f5-fea6-2992-a543-e4bd56822913", "locations": [ "[std7116_esx01] CISCAT-2016_CN-SKK/CISCAT-2016_.vmtx" ] }, { "entityName": "ind4481", "quiesced": true, "uuid": "500ae9dd-60e7-2339-4c4c-557ba00a3696", "locations": [ "[stx7116_esx01] ind4481/ind4481.vmx" ] }

我试过的:

response = requests.get('https://str001.example.com:8144/api/4.1/backups/'+y1, headers=headers, verify =False)
output = response.json()
data4 = output['response']['entities']

下面是我试图用 For 循环做的事情,并试图获得所需index但没有奏效:

for k in data4:
    x1 = (k['locations'].rsplit("]", 3)[-3].split("[")[-1],k['entityName'],k['quiesced'])
    print (x1)

期望输出

stx7116_esx01 CISCAT-2016_CN-SKK true
阿杰·辛格·拉纳

如果您提供的 json 对象是准确的,那么您可以尝试:

locations = []
for i in range(0,len(data4),1):
    data_dict = data4[i]     # each element is a separate dictionary
    location = data_dict['locations'][0]    # as locations is a list with a sngle item you'll have to extract it this way
    location =  location[location.find('[') + 1 : location.finct(']')]    # slice the string on range of the indexes of '[' and ']'
    desired_output = location + ' ' + data_dict['entityName'] + ' ' + data_dict['quiesced']

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用python从列表Json中获取数据?

从熊猫数据框中获取索引列表

如何在可选列表中的特定索引处获取元素?

如何获取数组列表中索引的大小?

如何在Python中从JSON API获取特定数据

如何获取位于列表中特定索引处的gameObject?

如何在JSON结果中获取特定数据

如何获取由R中的字符列表构成的特定长度的字符串的索引

在DataFrame中,如何获取特定列中带有0的索引列表?

如何使用python从列表中读取数据并将特定值索引到Elasticsearch中?

如何在Angular中获取特定的JSON数据

如何获取NSMutablearray中特定对象的索引?

如何从JSON列表中获取特定数据

如何从特定索引中获取数字?

我如何使用Angularjs从json数据中获取特定值

如何获取列表中字典的索引

如何获取列表中特定项目的最后一个索引?

如何使用 PHP 从 JSON 响应中获取特定数据

如何从嵌套的 JSON 中获取特定数据

如何在列表中获取 GameObject 索引?

如何获取列表中的索引

我如何使用 Retrofit 从 json 中获取数据作为列表

如何从数据框中获取以特定值开头的列列表?

如何从 Kotlin 列表列表中的特定索引创建列表?

如何从javascript中的JSON数据(URL)获取和存储特定值作为列表?

多索引熊猫数据框,如何获取特定索引列表

如何使用模型类在listview中获取json数据列表?

如何从groupby数据帧熊猫中获取索引列表

如何从数据框中获取基于特定模式的列列表