import requests
r = requests.get('test.com')
x=r.json()
print(x)
output is
{"test1":858,"test1":154343,"test":106091}
but x’s type is str, how to get key,value from x ? i want to get only 858
Advertisement
Answer
You can use the built-in json module:
import requests
import json
r = requests.get('test.com')
x = r.json()
print(json.loads(x)['test1'])
Output:
858