One alternative is to use the DataContractJsonSerializer instead of the JavascriptSerializer.
If you declare your classes like this:
[DataContract]
private class DeserializationMain
{
[DataMember(Name = "result")]
public string result; //works
[DataMember(Name = "arguments")]
public args arguments; //works, has deserialized activeTorrentCount
[DataContract]
public class args
{
[DataMember(Name = "activeTorrentCount")]
public int activeTorrentCount;
[DataMember(Name = "cumulative-stats")]
public current cumulative_stats; //doesn't work, equals null
[DataContract]
public class current
{
[DataMember(Name = "downloadedBytes")]
public long downloadedBytes;
}
}
}
You can deserialize it like this:
string json = "{"result":"success" , "arguments": { "activeTorrentCount":22, "cumulative-stats": { "downloadedBytes":1111 } } }";
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(DeserializationMain));
MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
DeserializationMain result = serializer.ReadObject(ms) as DeserializationMain;
Console.WriteLine("Cumulative-stats.downloadedBytes: "+result.arguments.cumulative_stats.downloadedBytes);
Will produce:
Cumulative-stats.downloadedBytes: 1111
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…