0
0

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 1 year has passed since last update.

API と JSON

Posted at

みにくい

import random
url = 'https://zipcloud.ibsnet.co.jp/api/search?zipcode=5450042'

result= requests.get(url)
data=json.loads(result.text)
print(data)
print(type(data))

{'message': None, 'results': [{'address1': '大阪府', 'address2': '大阪市阿倍
野区', 'address3': '丸山通', 'kana1': 'オオサカフ', 'kana2': 'オオサカシアベノク', 'kana3': 'マルヤマドオリ', 'prefcode': '27', 'zipcode': '5450042'}], 'status': 200}

みやすいくなるとき

import random
url = 'https://zipcloud.ibsnet.co.jp/api/search?zipcode=5450042'

result= requests.get(url)
data=json.loads(result.text)
pprint.pprint(data)
print(type(data))

{'message': None,
 'results': [{'address1': '大阪府',
              'address2': '大阪市阿倍野区',
              'address3': '丸山通',
              'kana1': 'オオサカフ',
              'kana2': 'オオサカシアベノク',
              'kana3': 'マルヤマドオリ',
              'prefcode': '27',
              'zipcode': '5450042'}],
 'status': 200}

形に変わります

import random
url = 'https://zipcloud.ibsnet.co.jp/api/search?zipcode=5450042'

result= requests.get(url)
data=json.loads(result.text)
pprint.pprint(data)
print(type(data))
pprint.pprint(data["results"])

[{'address1': '大阪府',
  'address2': '大阪市阿倍野区',
  'address3': '丸山通',
  'kana1': 'オオサカフ',
  'kana2': 'オオサカシアベノク',
  'kana3': 'マルヤマドオリ',
  'prefcode': '27',
  'zipcode': '5450042'}]

"[]" なくなりました

import random
url = 'https://zipcloud.ibsnet.co.jp/api/search?zipcode=5450042'

result= requests.get(url)
data=json.loads(result.text)
pprint.pprint(data)
print(type(data))
pprint.pprint(data["results"][0])

{'address1': '大阪府',
 'address2': '大阪市阿倍野区',
 'address3': '丸山通',
 'kana1': 'オオサカフ',
 'kana2': 'オオサカシアベノク',
 'kana3': 'マルヤマドオリ',
 'prefcode': '27',
 'zipcode': '5450042'}

郵便局を印刷された

import random
url = 'https://zipcloud.ibsnet.co.jp/api/search?zipcode=5450042'

result= requests.get(url)
data=json.loads(result.text)
pprint.pprint(data)
print(type(data))
json_data=data["results"][0]
print(f'郵便番号は{json_data["zipcode"]}')

'results': [{'address1': '大阪府',
              'address2': '大阪市阿倍野区',
              'address3': '丸山通',
              'kana1': 'オオサカフ',
              'kana2': 'オオサカシアベノク',
              'kana3': 'マルヤマドオリ',
              'prefcode': '27',
              'zipcode': '5450042'}],
 'status': 200}
<class 'dict'>
郵便番号は5450042

場所とかインフォメーションを印刷されるように

import random
url = 'https://zipcloud.ibsnet.co.jp/api/search?zipcode=5450042'

result= requests.get(url)
data=json.loads(result.text)
pprint.pprint(data)
print(type(data))
json_data=data["results"][0]
print(f'郵便番号は{json_data["zipcode"]}です。場所は{json_data["address1"]}{json_data["address2"]}{json_data["address3"]}です')

<class 'dict'>
郵便番号は5450042です。場所は大阪府大阪市阿倍野区丸山通です
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?