Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
API Abfrage
#1
Question 
Hallo zusammen, bin hier irwie am verzweifeln, vorweg ich bin noch nicht so lange dabei mich mit js auseinander zu setzen.

Ich frage eine Api ab und möchte dies in einer json Datei speichern. klappt auch soweit ganz gut, doch ist das was gespeichert wird zu viel für mich, also nicht relevantes zeug.

mein Code:
Code:
function getPriceList() {
    request(priceUrl, (error, response, body) => {
        if (error || response.statusCode !== 200) return console.log(`Error: ${error} - Status Code: ${response.statusCode}`);
        //console.log("DEBUG: " + body);
        fs.writeFileSync("prices.json", JSON.stringify(JSON.parse(body), null, 2));
       
    });
}

getPriceList();

prices.json Snippet:
Code:
{
  "status": "success",
  "prices": [
    {
      "app_id": "730",
      "context_id": "2",
      "market_hash_name": "'Blueberries' Buckshot | NSWC SEAL",
      "price": "1.71",
      "pricing_mode": "market",
      "skewness": "-0.49",
      "created_at": 1631410301,
      "icon_url": null,
      "name_color": null,
      "quality_color": null,
      "rarity_color": null,
      "instant_sale_price": null
    },
    {
      "app_id": "730",
      "context_id": "2",
      "market_hash_name": "'The Doctor' Romanov | Sabre",
      "price": "3.06",
      "pricing_mode": "market",
      "skewness": "-0.05",
      "created_at": 1631419491,
      "icon_url": null,
      "name_color": null,
      "quality_color": null,
      "rarity_color": null,
      "instant_sale_price": "1.22"
    },
    {
      "app_id": "730",
      "context_id": "2",
      "market_hash_name": "'Two Times' McCoy | TACP Cavalry",
      "price": "1.23",
      "pricing_mode": "market",
      "skewness": "-0.11",
      "created_at": 1631407484,
      "icon_url": null,
      "name_color": null,
      "quality_color": null,
      "rarity_color": null,
      "instant_sale_price": null
    }
  ]
}

meine Frage nun, ist es irgendiwe möglich, das nur noch dies:
Code:
{
  "'Blueberries' Buckshot | NSWC SEAL": 1.71,
  "'The Doctor' Romanov | Sabre": 3.06,
  "'Two Times' McCoy | TACP Cavalry": 1.23
}
in der prices.json Datei ankommt?

Also quasi der

"market_hash_name": price



mfG

André
Zitieren


Nachrichten in diesem Thema
API Abfrage - von CellSplitter - 12.09.2021, 22:45
RE: API Abfrage - von admin - 13.09.2021, 21:15
RE: API Abfrage - von Gast - 14.09.2021, 07:13
RE: API Abfrage - von admin - 14.09.2021, 17:20
RE: API Abfrage - von test - 14.09.2021, 17:37

Gehe zu:


Benutzer, die gerade dieses Thema anschauen:
1 Gast/Gäste