我们有哪些我试图解析,而通过读数据的JSON数据url
与json
&resquest
。
{ "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] 删除。
我来说两句