Hay un código json. Consistente por tipo: {"123":{...},"321":{...}} En él, necesita obtener "enlaces" de cada entrada. No pude entender esta nota, por favor ayúdame.
{ "3782474584475521065": { "listingid": "3782474584475521065", "price": 16, "asset": { "currency": 0, "appid": 730, "contextid": "2", "id": "25996697315", "amount": "1", "market_actions": [ { "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D2354938592644984102", "name": "Осмотреть в игре…" } ] } }, "3782474584475520325": { "listingid": "3782474584475520325", "price": 16, "asset": { "currency": 0, "appid": 730, "contextid": "2", "id": "25996698023", "amount": "1", "market_actions": [ { "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D9866835690490179400", "name": "Осмотреть в игре…" } ] } }}
Si entendí su pregunta correctamente, debe extraer los enlaces del texto json. Esta es una solución:
const a = { "3782474584475521065": { listingid: "3782474584475521065", price: 16, asset: { currency: 0, appid: 730, contextid: "2", id: "25996697315", amount: "1", market_actions: [ { link: "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D2354938592644984102", name: "Осмотреть в игре…", }, ], }, }, "3782474584475520325": { listingid: "3782474584475520325", price: 16, asset: { currency: 0, appid: 730, contextid: "2", id: "25996698023", amount: "1", market_actions: [ { link: "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D9866835690490179400", name: "Осмотреть в игре…", }, ], }, }, }; // get links from a const links = Object.values(a).map(({ asset }) => { const { market_actions } = asset; const { link } = market_actions[0]; return link; }); console.log(links);Esto simplemente itera a través de los valores del objeto y accede a los valores del enlace a través de la extracción del objeto.
Devuelve una matriz de objetos {id:link}
const data = { "3782474584475521065": { "listingid": "3782474584475521065", "price": 16, "asset": { "currency": 0, "appid": 730, "contextid": "2", "id": "25996697315", "amount": "1", "market_actions": [ { "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D2354938592644984102", "name": "Осмотреть в игре…" } ] } }, "3782474584475520325": { "listingid": "3782474584475520325", "price": 16, "asset": { "currency": 0, "appid": 730, "contextid": "2", "id": "25996698023", "amount": "1", "market_actions": [ { "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D9866835690490179400", "name": "Осмотреть в игре…" } ] } } } const result = Object.entries(data).map(([key, {asset, ...rest}]) => ({[key]: asset.market_actions[0].link})) console.log(result)