如何解析仅含数组与嵌套数组、无属性名的JSON数据?
How to Extract the First Number from Each Entry in That SteamCardExchange JSON
Got it, let's work through this together. That API returns a JSON object where each key is a unique identifier (like a game's AppID) and the corresponding value is an array—the first element of that array is exactly the number you need.
Here's a simplified look at the JSON structure:
{ "10": [0.05, "Counter-Strike", ...], "20": [0.10, "Team Fortress Classic", ...], "30": [0.15, "Day of Defeat", ...] }
Core Logic (Works for Any Language)
The steps are straightforward, no fancy identifiers needed:
- Fetch and parse the JSON into a native object/dictionary.
- Iterate over all the values of this object (each value is an array).
- Grab the first element (
index 0) from each array.
Example Code Snippets
Python
Using requests and json modules:
import json import requests # Fetch the API data response = requests.get("https://www.steamcardexchange.net/api/request.php?GetBadgePrices_Guest") # Parse JSON into a Python dictionary badge_data = json.loads(response.text) # Extract the first number from every entry first_numbers = [entry[0] for entry in badge_data.values()] # Use or print the result print(first_numbers)
JavaScript (Browser)
Using native fetch:
fetch('https://www.steamcardexchange.net/api/request.php?GetBadgePrices_Guest') .then(res => res.json()) .then(data => { // Pull the first element from each array value const firstNumbers = Object.values(data).map(entry => entry[0]); console.log(firstNumbers); }) .catch(err => console.error('Fetch error:', err));
JavaScript (Node.js)
Using axios (install first with npm install axios):
const axios = require('axios'); axios.get('https://www.steamcardexchange.net/api/request.php?GetBadgePrices_Guest') .then(res => { const firstNumbers = Object.values(res.data).map(entry => entry[0]); console.log(firstNumbers); }) .catch(err => console.error('Request error:', err));
The key insight here is that you don't need to worry about the keys (those random-looking identifiers) — you just care about the array values, and grabbing their first element is all it takes.
内容的提问来源于stack exchange,提问作者Zvrty
相关产品推荐
相关产品推荐

