How to I make use of an API return from a GET post?

William Thompson

New member
10.09.2024
1
0
BIT
13
I will post this first in English. I have this API request that is a GET request and it returns a massive JSON text. So, what is the easiest way to make the JSON file properly formatted and usable?
This is what the code looks like, by the way, that gets the massive text return.

Shall I repost this in Russian?

code-that-works.png
 

N1GGA

Codeby Team
Администратор
16.07.2018
357
351
BIT
413
C#:
using System;
using System.IO;
using System.Text.Json;

  string jsonString = "{\"name\":\"John\",\"age\":30,\"cars\":[\"Ford\",\"BMW\",\"Fiat\"]}"; // JSON DATA

        using (JsonDocument document = JsonDocument.Parse(jsonString))
        {
            string formattedJson = JsonSerializer.Serialize(document, new JsonSerializerOptions
            {
                WriteIndented = true
            });

            string filePath = "output.json";

            File.WriteAllText(filePath, formattedJson);

            Console.WriteLine("JSON saved to file: " + filePath);
        }
 
  • Нравится
Реакции: William Thompson
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!