Trying to deserialize this JSON:
{
"result":"success"
"arguments": {
"activeTorrentCount":22,
"cumulative-stats": {
"downloadedBytes":1111,
}
}
}
My class:
private class DeserializationMain
{
public string result; //works
public args arguments; //works, has deserialized activeTorrentCount
public class args
{
public int activeTorrentCount;
public current cumulative_stats; //doesn't work, equals null
public class current
{
public long downloadedBytes;
}
}
}
I guess cumulative-stats doesn’t get deserialized because it has cumulative_stats variable name in my class, how to deserialize that thing with a dash?
One alternative is to use the DataContractJsonSerializer instead of the JavascriptSerializer.
If you declare your classes like this:
You can deserialize it like this:
Will produce:
Cumulative-stats.downloadedBytes: 1111