pythonjson多层嵌套取值,使用Python从嵌套JSON对象中提取数据

更新时间:2023-05-30 01:59:32 阅读: 评论:0

pythonjson多层嵌套取值,使⽤Python从嵌套JSON对象中提取
长路迢迢数据
From this nested JSON object I need to par out and pretty print the value for "id" and the value for "location".
{
"links": {
"lf": "localhost:2510/api/v2/jobs?skills=data%20science"宝鸡天台山
},
"data": [
{
"id": 121,
"type": "job",
"attributes": {
老年礼品"title": "Data Scientist",
"date": "2014-01-22T15:25:00.000Z",
"description": "Data scientists are in increasingly high demand amongst tech companies in London. Generally a combination of business acumen and technical skills are sought. Big data experience ..."
},
"relationships": {
"location": {
"links": {
"lf": "localhost:2510/api/v2/jobs/121/location"
},
"data": {
"type": "location",
"id": 3
}
},
"country": {
"links": {
"lf": "localhost:2510/api/v2/jobs/121/country"
},
"data": {
"type": "country",
"id": 1
}
},
I've been trying to grab it in this way:
with open('data.json') as data_file:
data = json.load(data_file)
for item in data["data"]:新生儿排便
for job in data['id']:
for title in data['data']:
下水大佛
('location')
but I've not been able to grab the data I need.
How can I extract only tho datum that I'm interested in?
Edit
I've been trying this as some kind of exploration, but even this crashes before the file finishes:
import json
from pprint import pprint
with open('data.json') as data_file:
data = json.load(data_file)
for item in data["data"]:
for job in item:
凉拌红薯粉条print( job )
解决⽅案
形容人外貌的四字词语>谁是你的宝贝儿
I'm taking a leap and guessing the info you really want in the end, which is a list of item IDs for each location ID: import json
from collections import defaultdict
with open('') as data_file:
data = json.load(data_file)
locations = defaultdict(int)
for item in data['data']:
location = item['relationships']['location']['data']['id']
locations[location] += 1
print(locations)

本文发布于:2023-05-30 01:59:32,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/810434.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:外貌   四字   红薯
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图