简体   繁体   中英

How to select and print a specific JSON value using Python GET Request

I am attempting to select an save a specific 'identifier' value(392861) from a JSON url file after retrieving the JSON using a GET request:

getBooking = s.get("https://www.goodlifefitness.com/content/goodlife/en/book-workout/jcr:content/root/responsivegrid/workoutbooking.GetWorkoutSlots.7.2020-12-15.json")

I would like to store this specific 'identifier' value so I can send this value as part of a separate POST request.

Can you be more specific? Which "identifier" are you trying to access? Let's assume you want to access the dayOfWeek tag for each workout, then you can do something like this:

workouts_list = getBooking.json()["map"]["response"][0]["workouts"]
for workout in workouts_list:
    print(workout["dayOfWeek"])

You can do the same thing for other parameters as well by just replacing dayOfWeek to any of the tags available on the JSON response.

The following code retreived the information I was looking for.

workouts_list = getBooking.json()["map"]["response"][0]["workouts"] iden = workouts_list[0]["identifier"]

print(iden)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM