簡體   English   中英

如何從 json 響應中獲取特定字段值?

[英]How to fetch specific field value from the json response?

如何從 json 響應中獲取和打印發票 url 和商家名稱? 在 Python

這是我的有效載荷

import requests
import csv
from google.colab import files


url = "https://api.vdit.co/v2/invoices"

payload = "{\n\t\"external_id\": \"invoice-1597479693\",\n\t\"amount\": 3800000,\n\t\"payer_email\": \"customer@domain.com\",\n\t\"description\": \"Invoice Demo #1234\"\n}"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Basic sfdfsdfsdfdsfds==',
  'Cookie': 'visid_incap_2182539=9txMzsXTSfuzBolYeHI2Ui6hLl4AAAAAQUIPAAAAAABantpi5VKWQTh30yiNhG8y; nlbi_2182539=H15dNsiPqheQ/JGAjjCKbQAAAAAuILnoaVKZa2DtKg9G+o7E; incap_ses_1130_2182539=pdnQReH84gIVq2yWKJGuDz2aN18AAAAABIuVf37dWMch3rIN+1PZJg=='
}

response = requests.request("POST", url, headers=headers, data = payload)
print(response.text)

回復

"id":"5f38a9e14b73f4203a87465b","external_id":"invoice-1597479693","user_id":"5da7afcf5bf71e7c19d0a722","status":"PENDING","merchant_name":"PT Evi Asia Tenggara","merchant_profile_picture_url":"https://du8nwjtfkinx.cloudfront.net/vdit.png","amount":3800000,"payer_email":"customer@domain.com","description":"Invoice Demo #1234","expiry_date":"2020-08-17T03:37:05.746Z","invoice_url":"https://invoice-staging.vdit.co/web/invoices/5f38a9e14b73f4203a87465b","available_banks":[{"bank_code":"MANDIRI","collection_type":"POOL","bank_account_number":"8860848092927","transfer_amount":3800000,"bank_branch":"Virtual Account","account_holder_name":"PT ABC ASIA TENGGARA","identity_amount":0},{"bank_code":"BRI","collection_type":"POOL","bank_account_number":"2621556085816","transfer_amount":3800000,"bank_branch":"Virtual Account","account_holder_name":"PT ABV ASIA TENGGARA","identity_amount":0},{"bank_code":"BNI","collection_type":"POOL","bank_account_number":"880855854767","transfer_amount":3800000,"bank_branch":"Virtual Account","account_holder_name":"PT ABC ASIA TENGGARA","identity_amount":0},{"bank_code":"PERMATA","collection_type":"POOL","bank_account_number":"821457925493","transfer_amount":3800000,"bank_branch":"Virtual Account","account_holder_name":"PT  ASIA TENGGARA","identity_amount":0},{"bank_code":"BCA","collection_type":"POOL","bank_account_number":"1076620926923","transfer_amount":3800000,"bank_branch":"Virtual Account","account_holder_name":"PT ABC ASIA TENGGARA","identity_amount":0}],"available_ewallets":[],"should_exclude_credit_card":false,"should_send_email":false,"created":"2020-08-16T03:37:05.804Z","updated":"2020-08-16T03:37:05.804Z","currency":"IDR"}
JSON received:

如何從 json 響應中獲取和打印發票 url 和商家名稱? 在 Python

我希望結果是這樣的,請指導我

發票 Url:“https://invoice-staging.vdit.co/web/invoices/5f38a9e14b73f4203a87465b” 商家名稱:PT ABC ASIA TENGGARA

提前致謝

像這樣的東西應該工作

resp = response.json()
invoice_url = resp['invoice_url']
merchant_name = resp['merchant_name']
print(invoice_url, marchant_name)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM