Python 无法解析JSON文件中特定标记的所有实例
我这里有一个JSON。问题是JSON有3个“description”标记,但对于第一条记录,我只能读取一次。我无法移动到所有“描述”标记并从中读取描述。在我这里的代码中,我已经能够计算出“description”标记的3个实例,但无法通读所有实例。此处的For循环在所有3个位置重复第一个标记的内容。请帮忙 代码: 示例JSON:Python 无法解析JSON文件中特定标记的所有实例,python,json,python-3.x,python-requests,Python,Json,Python 3.x,Python Requests,我这里有一个JSON。问题是JSON有3个“description”标记,但对于第一条记录,我只能读取一次。我无法移动到所有“描述”标记并从中读取描述。在我这里的代码中,我已经能够计算出“description”标记的3个实例,但无法通读所有实例。此处的For循环在所有3个位置重复第一个标记的内容。请帮忙 代码: 示例JSON: { "isError": false, "message": "SUCCESS", "statusCode": 200, "data": { "
{
"isError": false,
"message": "SUCCESS",
"statusCode": 200,
"data": {
"job": [
{
"dates": {
"firstseen": "1991-01-13",
"lastseen": "1991-02-23"
},
"title": {
"value": "Holland(ALPHA) – Color Line",
"translation": "Holland(ALPHA) - Color Line",
"titleid": 896616466,
"cleantitleid": 12087238,
"semicleantitleid": 349366870
},
"description": {
"value": "Holland(ALPHA) is in foreign language.",
"translation": "Holland(ALPHA) is in English"
},
"requirements": {
"value": "",
"translation": null
},
"education": {
"id": 5,
"label": "Bachelor's degree"
},
"jobTypes": {
"jobType": [
{
"id": "4",
"label": "Full-Time"
},
{
"id": "1",
"label": "Permanent"
}
]
},
"skillslist": {
"element": [
{
"id": 30925,
"label": "Negotiation",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 37810,
"label": "Information technology",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 38451,
"label": "Architecture",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 36710,
"label": "Collaboration",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 36712,
"label": "Best practices",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 33674,
"label": "Budgeting",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 40628,
"label": "Trust development",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
}
]
},
"seniority": {
"id": 2,
"label": "Mid-level "
},
"employer": {
"id": "4485465",
"name": "Color Line",
"superaliasid": "4485465",
"superalias": "Color Line",
"translation": "Color Line"
},
"locations": {
"location": [
{
"city": {
"id": 3860366,
"code": "",
"label": "Oslo",
"translation": "Oslo"
},
"state": {
"id": 4419,
"code": "",
"acronym": null,
"label": "Oslo and Akershus",
"translation": "Oslo and Akershus"
},
"county": {
"id": 0,
"code": "",
"label": "Unavailable"
},
"wib": {
"id": 0,
"code": "00000",
"label": "Unavailable"
},
"msa": {
"id": 8022,
"code": "",
"label": "Oslo",
"translation": "Oslo"
},
"superregion": {
"id": 0,
"code": "00",
"label": "Unavailable"
},
"country": {
"id": 169,
"code": "NO",
"label": "Norway"
},
"position": {
"latitude": "59.975399017333984",
"longitude": "10.738800048828125"
}
}
]
},
"salaries": {
"salary": [
{
"id": 2,
"type": "Modeled",
"value": 0
}
]
},
"sources": {
"source": [
{
"id": 136623,
"jobid": "4187345693",
"tags": "",
"type": "4",
"name": "CV Norway",
"url": "XXX",
"validlink": true
}
]
},
"occupation": {
"occupation": {
"id": 10011,
"code": "11302100",
"label": "Computer and Information Systems ",
"revision": "2011",
"option": null
}
}
},
{
"dates": {
"firstseen": "1991-01-09",
"lastseen": "1991-02-22"
},
"title": {
"value": "Holland(H/F)",
"translation": "Alpha",
"titleid": 321624492,
"cleantitleid": 12087238,
"semicleantitleid": 36908
},
"description": {
"value": "Accueil » HOLLAND(H/F) in French",
"translation": "Home\" HOLLAND(H/F) in English
},
"requirements": {
"value": "",
"translation": null
},
"education": {
"id": 5,
"label": "Bachelor's degree"
},
"jobTypes": {
"jobType": [
{
"id": "4",
"label": "Full-Time"
},
{
"id": "1",
"label": "Permanent"
}
]
},
"skillslist": {
"element": [
{
"id": 34182,
"label": "Responsibility",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 31350,
"label": "Release management",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 44384,
"label": "Writing",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 38029,
"label": "High Availability",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 31877,
"label": "Continuous integration",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 38495,
"label": "Deployments",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 41023,
"label": "Service delivery",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 38534,
"label": "Optimization",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 40843,
"label": "Communication systems",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 26898,
"label": "Project management",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 41138,
"label": "Storage engineering",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 31219,
"label": "Decision making",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 31041,
"label": "DevOps",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 26428,
"label": "Database administration",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 33469,
"label": "Security engineering",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 40706,
"label": "Security",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 36216,
"label": "Financial engineering",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 34399,
"label": "Software development",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 37389,
"label": "Programming",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 18409,
"label": "Application management",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 39726,
"label": "Project management office",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 42440,
"label": "Help desk",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 42441,
"label": "Hosting",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 37410,
"label": "Databases",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 26477,
"label": "Search Engine Optimization",
"translation": "",
"acronym": "SEO",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 26991,
"label": "System administration",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 44180,
"label": "Design",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 40890,
"label": "Hardware",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 38451,
"label": "Architecture",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 44177,
"label": "Dedication",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 40135,
"label": "Telecommunications engineering",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 43917,
"label": "Presales",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 44294,
"label": "Organizational change",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 39941,
"label": "E-commerce",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 33602,
"label": "Internet marketing",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 18792,
"label": "Network management",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 31134,
"label": "Adaptability",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 34489,
"label": "Middleware",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 31098,
"label": "Organizational skills",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 30962,
"label": "Technical documentation",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 40871,
"label": "Systems management",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 40757,
"label": "Integrations",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 31001,
"label": "Leadership",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 37622,
"label": "Software architecture",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 43580,
"label": "Supply chain",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
}
]
},
"seniority": {
"id": 1,
"label": "Junior (0-2 yrs)"
},
"employer": {
"id": "27642083",
"name": "TOMORROW JOBS",
"superaliasid": "27642083",
"superalias": "TOMORROW JOBS",
"translation": "TOMORROW JOBS"
},
"locations": {
"location": [
{
"city": {
"id": 3080771,
"code": "",
"label": "Nancy",
"translation": "Nancy"
},
"state": {
"id": 4056,
"code": "",
"acronym": null,
"label": "Meurthe-et-Moselle",
"translation": "Meurthe-et-Moselle"
},
"county": {
"id": 0,
"code": "",
"label": "Unavailable"
},
"wib": {
"id": 0,
"code": "00000",
"label": "Unavailable"
},
"msa": {
"id": 4381,
"code": "",
"label": "Nancy",
"translation": "Nancy"
},
"superregion": {
"id": 0,
"code": "00",
"label": "Unavailable"
},
"country": {
"id": 80,
"code": "FR",
"label": "France"
},
"position": {
"latitude": "48.692100524902344",
"longitude": "6.187759876251221"
}
}
]
},
"salaries": {
"salary": [
{
"id": 2,
"type": "Modeled",
"value": 77000
},
{
"id": 3,
"type": "FR",
"value": 131600
}
]
},
"sources": {
"source": [
{
"id": 113426,
"jobid": "4242870269",
"tags": "",
"type": "6",
"name": "jobintree",
"url": "https://bbb",
"validlink": true
}
]
},
"occupation": {
"occupation": {
"id": 10011,
"code": "11302100",
"label": "Computer and Information Systems Managers",
"revision": "2011",
"option": null
}
}
},
{
"dates": {
"firstseen": "1991-01-08",
"lastseen": "1991-02-23"
},
"title": {
"value": "ALPHA (ALPHA)",
"translation": "ALPHA (ALPHA)",
"titleid": 6083482,
"cleantitleid": 12578212,
"semicleantitleid": 78683
},
"description": {
"value": "last one is english",
"translation": null
},
"requirements": {
"value": "",
"translation": null
},
"education": {
"id": 5,
"label": "Bachelor's degree"
},
"jobTypes": {
"jobType": [
{
"id": "4",
"label": "Full-Time"
},
{
"id": "1",
"label": "Permanent"
}
]
},
"skillslist": {
"element": [
{
"id": 34346,
"label": "Research",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
},
{
"id": 31057,
"label": "Enterprise architecture",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 37542,
"label": "Computer science",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 34399,
"label": "Software development",
"translation": "",
"acronym": "",
"code": "",
"type": "TECH",
"count": 0
},
{
"id": 38566,
"label": "Validation",
"translation": "",
"acronym": "",
"code": "",
"type": "SOFT",
"count": 0
}
]
},
"seniority": {
"id": 3,
"label": "Senior (8+ yrs)"
},
"employer": {
"id": "24832370",
"name": "Medisyskart.com",
"superaliasid": "24832370",
"superalias": "Medisyskart.com",
"translation": "Medisyskart.com"
},
"locations": {
"location": [
{
"city": {
"id": 3198431,
"code": "",
"label": "Chennai",
"translation": "Chennai"
},
"state": {
"id": 1675,
"code": "",
"acronym": null,
"label": "Tamil Nādu",
"translation": "Tamil Nādu"
},
"county": {
"id": 23810,
"code": "",
"label": "Chennai"
},
"wib": {
"id": 0,
"code": "00000",
"label": "Unavailable"
},
"msa": {
"id": 6154,
"code": "",
"label": "Chennai",
"translation": "Chennai"
},
"superregion": {
"id": 0,
"code": "00",
"label": "Unavailable"
},
"country": {
"id": 107,
"code": "IN",
"label": "India"
},
"position": {
"latitude": "13.084600448608398",
"longitude": "80.24839782714844"
}
}
]
},
"salaries": {
"salary": [
{
"id": 2,
"type": "Modeled",
"value": 1469000
},
{
"id": 3,
"type": "IN",
"value": 131600
}
]
},
"sources": {
"source": [
{
"id": 113727,
"jobid": "4175725226",
"tags": "",
"type": "5",
"name": "Shine",
"url": "sss/",
"validlink": true
}
]
},
"occupation": {
"occupation": {
"id": 10011,
"code": "11302100",
"label": "Computer and Information Systems Managers",
"revision": "2011",
"option": null
}
}
}
]
},
"IgnoreLocalCache": true
}
''根据我对您项目需求的理解,您不需要两本字典。只有一个,您可以这样循环:
newDictionary=json.loads(str(url))
x = newDictionary['data']['job']
#for every item in ['data']['job']
for job in x:
# print the translation if ['description']['translation'] doesn't equal None
if job['description']['translation'] != None:
print (job['description']['translation'])
#else print the value in job['description']
else:
print(job['description']['value'])
newDictionary=json.loads(str(url))
x = newDictionary['data']['job']
#for every item in ['data']['job']
for job in x:
# print the translation if ['description']['translation'] doesn't equal None
if job['description']['translation'] != None:
print (job['description']['translation'])
#else print the value in job['description']
else:
print(job['description']['value'])