I'm currently using JSON.NET to get info from several web APIs, as explained to me in a previous q&a. But now I've stumbled upon another kind of web API that I can't parse because I don't know how to. This is the one: https://data.bter.com/api/1/tickers
As you can see, it's a json collection of trading pairs. But the collection itself is unnamed, so I'd have to make a class for each trading pair, which isn't really dynamic. I'm using the following to parse the url:
public static T DownloadSerializedApi<T>(string address) where T : new()
{
T newT = new T();
HttpClient client = new HttpClient();
using (Stream s = client.GetStreamAsync(address).Result)
using (StreamReader sr = new StreamReader(s))
using (JsonReader reader = new JsonTextReader(sr))
{
JsonSerializer serializer = new JsonSerializer();
newT = serializer.Deserialize<T>(reader);
}
return newT;
}
Now I'd like to set T as class "TradingPairs" in which there would be a list with all tradingpairs. But the way I see it now, it will be a long list of hardcoded pairs :(
Anyone care to help me? ;)
Pair
with the appropriate properties and map the json to those properties using theJsonProperty
attribute. When I get back to my desk I'll provide a more complete solution. – jebar8 Jun 21 at 3:47