Muthu vj

Muthu vj

  • 1.6k
  • 162
  • 9.2k

Input string was not in a correct format

Apr 29 2021 4:29 PM
hi,
 
{ "endpoint": "live", "quotes": [ { "ask": 1.21153, "base_currency": "EUR", "bid": 1.21153, "mid": 1.21153, "quote_currency": "USD" }, { "ask": 1.39483, "base_currency": "GBP", "bid": 1.39481, "mid": 1.39482, "quote_currency": "USD" } ], "requested_time": "Thu, 29 Apr 2021 16:19:11 GMT", "timestamp": 1619713151 }
 
this is my Result i want to get the output from API and deserialized it i tried it but got the
 
Input string was not in a correct format: c#
 
Error can you help me on that
  1. private async void getCurrentPrize() {  
  2.     HttpClient client = new HttpClient(); //  
  3.     HttpResponseMessage response = await client.GetAsync("https://financialmodelingprep.com/api/v3/fx/EURUSD,USDINR,USDCAD,XAUUSD,XAGUSD,GBPUSD,EURJPY,AUDUSD?apikey=xxxxxxxxxxxxxxxxxxxx");  
  4.     HttpResponseMessage response = await client.GetAsync("https://marketdata.tradermade.com/api/v1/live?currency=EURUSD,GBPUSD&api_key=_xxxxxxxxxxxxx");  
  5.     response.EnsureSuccessStatusCode();  
  6.     var responseBody = await response.Content.ReadAsStringAsync();  
  7.     var result = JsonConvert.DeserializeObject < CurrencyDetails > (responseBody);  
  8.     CurrencyDetails deserialized = new CurrencyDetails();  
  9.     foreach(var item in result.quotes) { //my logic here }  
  1. public class CurrencyDetails {  
  2.   public string endpoint {  
  3.     get;  
  4.     set;  
  5.   }  
  6.   public List < quotes > quotes {  
  7.     get;  
  8.     set;  
  9.   }  
  10.   public string requested_time {  
  11.     get;  
  12.     set;  
  13.   }  
  14.   public long timestamp {  
  15.     get;  
  16.     set;  
  17.   }  
  18. }  
  1. public class quotes {  
  2.   public double ask {  
  3.     get;  
  4.     set;  
  5.   }  
  6.   public double bid {  
  7.     get;  
  8.     set;  
  9.   }  
  10.   public string base_currency {  
  11.     get;  
  12.     set;  
  13.   }  
  14.   public double mid {  
  15.     get;  
  16.     set;  
  17.   }  
  18.   public string quote_currency {  
  19.     get;  
  20.     set;  
  21.   }  
  22. }  

Answers (3)