JSONの特定の値のみを取得する
下記にコードとレスポンスを掲載します。
レスポンスの情報が多すぎて、情報を削りたいと考えています。
必要なのは、name と email のみですが、どの様にそれのみを抽出するべきでしょうか。
ご教示のほど、何卒よろしくお願いいたします。
追記
print(data)
を print(["name"])
とした場合は
KeyError: 'name' が返ってきしまいます。
request
1response = requests.get(url, auth=(user,pwd)) 2 3import requests 4 5url = "https://domain.zendesk.com/api/v2/users.json?page=" 6user = "test@test.com" + "/token" 7pwd = "abcdefghijklmn" 8 9response = requests.get(url, auth=(user,pwd)) 10pagination = 1 11 12while response.status_code == 200: 13 url + str(pagination) 14 response = requests.get(url, auth=(user,pwd)) 15 data = response.json() 16 print(data) 17 pagination += 1
resuponse
1{"users":[ 2 { 3 "id": 12345, 4 "url": "https://test.json", 5 "name": "test", 6 "email": "test123@test.com", 7 "created_at": "2019", 8 "updated_at": "2019", 9 "time_zone": "Tokyo", 10 "iana_time_zone": "Asia/Tokyo", 11 "phone": "None", 12 "shared_phone_number": "None", 13 "photo": "None", 14 "locale_id": 1, 15 "locale": "ja", 16 "organization_id": "None", 17 "role": "end-user", 18 "verified": "False", 19 "external_id": "None", 20 "tags": [], 21 "alias": "None", 22 "active": "True", 23 "shared": "False", 24 "shared_agent": "False", 25 "last_login_at": "None", 26 "two_factor_auth_enabled": "False", 27 "signature": "None", 28 "details": "None", 29 "notes": "None", 30 "role_type": "None", 31 "custom_role_id": "None", 32 "moderator": "False", 33 "ticket_restriction": "requested", 34 "only_private_comments": "False", 35 "restricted_agent": "True", 36 "suspended": "False", 37 "chat_only": "False", 38 "default_group_id": "None", 39 "report_csv": "False", 40 "user_fields": {} 41}, 42 { 43 "id": 12345, 44 "url": "https://test.json", 45 "name": "test", 46 "email": "test123@test.com", 47 "created_at": "2019", 48 "updated_at": "2019", 49 "time_zone": "Tokyo", 50 "iana_time_zone": "Asia/Tokyo", 51 "phone": "None", 52 "shared_phone_number": "None", 53 "photo": "None", 54 "locale_id": 1, 55 "locale": "ja", 56 "organization_id": "None", 57 "role": "end-user", 58 "verified": "False", 59 "external_id": "None", 60 "tags": [], 61 "alias": "None", 62 "active": "True", 63 "shared": "False", 64 "shared_agent": "False", 65 "last_login_at": "None", 66 "two_factor_auth_enabled": "False", 67 "signature": "None", 68 "details": "None", 69 "notes": "None", 70 "role_type": "None", 71 "custom_role_id": "None", 72 "moderator": "False", 73 "ticket_restriction": "requested", 74 "only_private_comments": "False", 75 "restricted_agent": "True", 76 "suspended": "False", 77 "chat_only": "False", 78 "default_group_id": "None", 79 "report_csv": "False", 80 "user_fields": {} 81} 82] 83}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/12/20 07:48
退会済みユーザー
2019/12/20 08:41