I need to deserialize a json back to object instance using Newtonsoft.Json.
However, it is a list type object and the key of the entry is useful to me.
I don't know how to deserialize automatically without mapping the fields one by one manually.
Here is the response:
{
coins: {
365Coin: {
id: 74,
tag: "365",
algorithm: "Keccak",
lagging: true,
listed: false,
status: "No available stats",
testing: false
},
Aiden: {
id: 65,
tag: "ADN",
algorithm: "Scrypt-OG",
lagging: true,
listed: false,
status: "No available stats",
testing: false
},
Adzcoin: {
id: 157,
tag: "ADZ",
algorithm: "X11",
lagging: false,
listed: false,
status: "Active",
testing: false
}
... [With various key representing the name of coins]
}
}
The full response: https://whattomine.com/calculators.json
My best guess of the class is somethings like:
internal class WhatToMineCalculatorsResponse
{
// Should be Dictionary???
[JsonProperty("coins")]
public IList<WhatToMineCalculatorResponse> Coins { get; set; }
}
internal class WhatToMineCalculatorResponse
{
// I want the key set in this field
public string Name { get; set; }
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("tag")]
public string Symbol { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("algorithm")]
public string Algo { get; set; }
[JsonProperty("listed")]
public bool IsListed { get; set; }
}
Note that I want the key included in my class but not as the key of a dictionary. It's hard to retrieve the key later.