Advertisement
wofus

SPR

Mar 9th, 2022
1,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using JSON;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Net;
  7.  
  8. namespace Spritpreisrechner
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             preise();
  15.         }
  16.  
  17.         private static void preise()
  18.         {
  19.             string json;
  20.  
  21.             var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.150201766714105&longitude=16.319807691015892&fuelType=SUP&includeClosed=false");
  22.             httpWebRequest.ContentType = "text/json";
  23.             httpWebRequest.Method = "GET";
  24.  
  25.             var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  26.             using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
  27.             {
  28.                 var responseText = streamReader.ReadToEnd();
  29.                 json = responseText;
  30.             }
  31.  
  32.             var result = JsonConvert.DeserializeObject<List<Price>>(json);
  33.  
  34.             //Console.WriteLine(result.Count);
  35.  
  36.             foreach (var preis in result)
  37.             {
  38.                 Console.WriteLine(preis.Amount);
  39.             }
  40.  
  41.             Console.Read();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement