0

I am trying to separate this response in python:

{"token":"20906d71687539386c766a696a6a6231616f6c62736d71687539386c67697576307734313339363936363463366336363533373434333536343134353337366237613339343233303664373236613737353935613431363436 39333634383331333533383335333033393337333733383331323061623564356233373030646337383534656466383235616134613636353661396439363662326633313532396165353865393836636332363038303736643135383530 3937373831","landed_at":"1585097781"}

I want to make a variable for token and have it hold the "token" value and a variable for landed_at and have it hold that value.

sloshy
  • 29
  • 4

2 Answers2

1

You should be able to do this using the json lib.

import json
raw = '{"token":"20906d716875391","landed_at":"1585097781"}'
jsonObj = json.loads(raw)
token = jsonObj['token']
landedat = jsonObj['landed_at']
token
#'20906d716875391'
Ian-Fogelman
  • 1,595
  • 1
  • 9
  • 15
0

You can do that by accessing the simple dictionary object you are working with. Assuming your response is the object resp:

resp = {"token": "1221234213", "landed_at" : "1585097781"}
token = resp["token"]
landed_at = resp["landed_at"]

This is how you access the values in a dictionary, by calling the key of that value.

katardin
  • 596
  • 3
  • 14