Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6594235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:47:05+00:00 2026-05-25T17:47:05+00:00

Trying to deserialize this JSON: { result:success arguments: { activeTorrentCount:22, cumulative-stats: { downloadedBytes:1111, }

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:47:05+00:00Added an answer on May 25, 2026 at 5:47 pm

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use eval() function to deserialize this JSON text by using
I'm trying to deserialize sample JSON at the end of this question with below.
I am trying to deserialize a JSON String like (extracted this bit to show
I am trying to use the example in this link http://sharpdevpt.blogspot.com/2009/10/deserialize-json-on-c.html?showComment=1265045828773#c2497312518008004159 But my project
I am trying to deserialize a stream but I always get this error End
I'm trying to deserialize an xml structure that looks like this: <somecontainer> <key1>Value1</key1> <key1>Value2</key1>
I'm trying to deserialize json to an object model where the collections are represented
I'm trying to deserialize/serialize a timespan with Newtonsoft.Json.JsonConvert , but when the JSON is
I am trying to deserialize a json response from a google api, so i
I'm trying to deserialize a json response and am getting the value cannot be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.