Python Api parsing Json problem
-
- PrecatorBaxter [3288988]
- Role: Civilian
- Level: 18
- Posts: 29
- Karma: 3
- Last Action: 10 months
Thread created on 19:25:26 - 15/05/24 (11 months ago)|Last replied 10:39:48 - 16/05/24 (11 months ago)I am using this endpoint > https://api.torn.com/torn/?selections=items&key=
I see all the items in the browser, but I am having problems.
response = requests.get("https://api.torn.com/torn/?selections=items&key=" + key)
json_data = json.dumps(response.text)
After this I am having a problem. I want to loop over each item and loop over the results and print the market_value variable. I know I am supposed to do like for x in json_data but it seems to get stuck on the top level items dict i believe. Sorry I am new to Python and just trying to figure this out. -
Posted on 20:33:51 - 15/05/24 (11 months ago)Post link copied to clipboard Copy post linkIf you're using requests, you can use response.json()
That will return a python object you can iterate over.Last edited by pobk on 20:34:27 - 15/05/24 (11 months ago)~ P
Support my suggestions: Faction API Keys
-
-
Posted on 04:06:00 - 16/05/24 (11 months ago)Post link copied to clipboard Copy post linkYou should check what the value in json_data is (using print or a debugger) since the API response has a with an "items" key. You can use https://tornapi.tornplayground.eu/torn/items to see the full response format. So you'd have to use something like..
I wish Ched had code formatting in forums... -
-
- PrecatorBaxter [3288988]
- Role: Civilian
- Level: 18
- Posts: 29
- Karma: 3
- Last Action: 10 months
Posted on 10:39:48 - 16/05/24 (11 months ago)Post link copied to clipboard Copy post linkThanks alot this worked!