Search code examples
c#apihttpjson-deserializationcsharpcodeprovider

JSON TO C# Deserializing


Can someone help me deserialize JSON from this api https://www.freeforexapi.com/api/live?pairs=EURUSD,GBPUSD to a C# Object? I have tried many ways and examples I found online, non seems to be working


Solution

  • Here rates is Map, So Response C# class look like this:

    public class Response
    {
        public Dictionary<string, Rate> Rates{get;set;}
        public int Code {get;set;} 
    }
    
    public class Rate
    {
        public double Rate { get; set; }
        public long TimeStamp { get; set; }
    
    }
    

    To deserialize :

    var obj = JsonConvert.DeserializeObject<Response>(jsonObject);