S
S
Sanchoys2282020-08-14 12:31:10
Python
Sanchoys228, 2020-08-14 12:31:10

How to tell python to read received text from website in json format?

Through the api site market.csgo.com I get the text:

kp_online_req = requests.get("https://market.csgo.com/api/v2/ping?key=" + api)
print(kp_online_req.text)


5f365942d3000305328236.png
How to indicate that the text is json

I need to get the success element values

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SKEPTIC, 2020-08-14
@pro100chel

print(kp_online_req.json()['success'])

A
Alexander, 2020-08-14
@NeiroNx

kp_online_req = requests.get("https://market.csgo.com/api/v2/ping?key=" + api).json()
print(kp_online_req['success'])

T
tkillamsk, 2020-08-14
@tkillamsk

import requests
import json

kp_online_req = requests.get("https://market.csgo.com/api/v2/ping?key=" + api)
json_ = json.loads(kp_online_req.text)
print(json_)

the received text from the site must be read in json format

json is a string, to work with the json structure you need to convert it to a dictionary via json.dumps(). Then you can access json elements as elements of a dictionary by key-value. I guess the question was about it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question