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
JSON TO C# Deserializing
55 views Asked by Ithra At
2
There are 2 answers
0
On
for example, using newtonsoft json create class for response
public class EURUSD {
public double rate { get; set; }
public int timestamp { get; set; }
}
public class GBPUSD {
public double rate { get; set; }
public int timestamp { get; set; }
}
public class Rates {
public EURUSD EURUSD { get; set; }
public GBPUSD GBPUSD { get; set; }
}
public class Root {
public Rates rates { get; set; }
public int code { get; set; }
}
and then deserialize response, like
Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
you may use json2csharp website to easy generate classes like this^
Here rates is Map, So Response C# class look like this:
To deserialize :