나는 내가 부르고있는 API에서 다음 JSON 파일이 있습니다 ""14500 "파이썬 톱 레벨의 JSON 지수
{
"14500": [
{
"5": {
"versionName": "VersionOne",
"expand": "executionSummaries",
"name": "Regression",
"projectId": 15006,
"startDate": "",
"executionSummaries": {
"executionSummary": []
}
},
"7": {
"versionName": "VersionOne",
"expand": "executionSummaries",
"versionId": 14500,
"projectId": 15006,
"startDate": "19/Sep/16",
"executionSummaries": {
"executionSummary": []
}
},
"-1": {
"versionName": "VersionOne",
"expand": "executionSummaries",
"name": "Ad hoc",
"modifiedBy": "",
"projectId": 15006,
"startDate": "",
"executionSummaries": {
"executionSummary": []
}
},
"recordsCount": 3
}
],
"14501": [
{
"-1": {
"versionName": "Version 2",
"expand": "executionSummaries",
"projectId": 15006,
"startDate": "",
"executionSummaries": {
"executionSummary": []
}
},
"recordsCount": 1
}
],
}
내가, 최상위 레벨을 반복해야하고 다음 단계 (예를합니다. 5 ","7 "등)을 사용하여 키와 값을 찾습니다. 예를 들어 전체 JSON 파일을 검색하여 "회귀 분석"과 일치하는 이름을 찾고 "ProjectID"및 기타 문자열에 대한 해당 데이터 세트 집합을 찾아야합니다. 이전에 데이터 [ "level1"] [0] [ "level2"] 등을 사용하여이 작업을 수행했지만,이 경우 숫자는 결코 같지 않으므로 전화하는 법을 모르겠습니다. 여기에 몇 가지 게시물을 살펴본 후 다음을 작성했지만 JSON의 다음 단계가 아닌 한 단계에서만 작동합니다.
request = requests.get(getCyclesURL, headers=headers)
requestData = json.loads(request.text)
requestDataKeys = requestData.keys
for k in requestDataKeys():
dictionaryIDs = requestData[k]
for m in requestDataKeys:
newDictionaryIDs = requestData[k][m]
for dict in newDictionaryIDs:
if dict['versionName'] == versionName:
versionID = dict['versionID']
print '%s: %s'%(versionName, versionID)
@MMF 그것은 할당시 메서드를 호출하지 않았으므로 수행합니다. – jonrsharpe