この入れ子になったJSONオブジェクトから、"id"
の値と"location"
の値を解析して出力する必要があります。pythonを使用して入れ子になったjsonオブジェクトからデータを外科的に抽出
{
"links": {
"self": "http://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": {
"self": "http://localhost:2510/api/v2/jobs/121/location"
},
"data": {
"type": "location",
"id": 3
}
},
"country": {
"links": {
"self": "http://localhost:2510/api/v2/jobs/121/country"
},
"data": {
"type": "country",
"id": 1
}
},
私はこの方法でそれをつかむしようとしてきた:
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']:
print(title.get('location')
が、私は私が必要とするデータをつかむことができていませんでした。
興味のあるデータのみを外科的に抽出するにはどうすればよいですか?
EDIT
私は探検のいくつかの種類として、これをしようとしてきたが、それでもこれは、ファイルが終了する前にクラッシュ:
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)
ええ、私はそれ以来変わってきました。 **編集の下に新しいコードを入れます** –
あなたのコードをコピーしてファイルをダウンロードしてもエラーは発生しません。 –
ああ - ええ - 私はそれを書いてから変更しました。まだ私は私が探しているものを得ることができません。これは、データのアイテム[data "]のようになります。アイテムの属性:属性のタイトル['title']:print(title)'実際に取得しようとしているのは、 id –