Qiita Conference 2025

徳丸浩 (@ockeghem)

60歳を超えて現役エンジニアであり続けるために心がけていること

0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

keyとvalueについて-media_url取得までの流れ

Posted at

型について

# terminal上で取得している
{'data': [{'id': '1234567890', 'media_type': 'IMAGE', 
'media_url':'https://test.com/', 
'timestamp': '2021********', 'username': 'qiita'}], 
'paging': {'cursors': {'before': 'abcd', 'after': 'abcd'}}}

このdataは辞書型{}とリスト型[]が存在している。
今回は仮定として変数を profile_data ということにする。

最初に'data'を取得してみる

>>>profile_data['data']
[{'id': '1234567890', 'media_type': 'IMAGE', 'media_url':'https://test.com/', 
'timestamp': '2021********', 'username': 'qiita'}]

commandでprofile_data['data']と入力すると元の情報からdataの部分だけが抽出される。
先頭の辞書型がなくなり、[{}]の型に変化した

次に何個目の情報を取得するのかを指定する

>>>profile_data['data'][0]
{'id': '1234567890', 'media_type': 'IMAGE', 'media_url':'https://test.com/', 
'timestamp': '2021********', 'username': 'qiita'}

comandに[0]を追加することにより、何個目の情報を取得するのかを指定できる。今回は1つしかないため[0]を使用した。

最後にmedia_urlを取得する

>>>profile_data['data'][0]['media_url']
'https://test-qiita.com/'

'media_url'を追加し取得する。今回は'media_url'だったが、'id'、'media_type'でも同様のことが可能である。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?