0
{
"destination_addresses" : [ "Saskatoon, SK, Canada" ],
"origin_addresses" : [ "Asquith, SK S0K 0J0, Canada" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "39.5 km",
"value" : 39512
},
"duration" : {
"text" : "33 mins",
"value" : 1950
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
apisから特定の情報にアクセスする方法がわかりません。上記の例では、距離と継続時間の両方の値とステータス値を取り出す必要があります。この私が現在持っているものです:あなたは出力配列を反復処理する必要がありますAPIリクエストで特定の情報にアクセスする方法 - Python
import requests
import urllib.parse
main_api = "https://maps.googleapis.com/maps/api/distancematrix/json?"
units = "metric"
print("Example: Origin = Biggar, SK\nDestination = Saskatoon, SK")
origin = str(input("Please enter your origin: "))
destination = str(input("Please enter your destination: "))
url = main_api + urllib.parse.urlencode({"units": units, "origins": origin,
"destinations": destination})
print(url)
json_data = requests.get(url).json()
print(json_data[])