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 5998277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:22:59+00:00 2026-05-23T00:22:59+00:00

I have this JSON: { AutoRefreshEnabled : false, AutoRefreshInterval : 1, AutoCycleEnabled : false,

  • 0

I have this JSON:

{
    "AutoRefreshEnabled" : false,
    "AutoRefreshInterval" : 1,
    "AutoCycleEnabled" : false,
    "AutoCycleInterval" : 1,
    "Tabs" : {
        "RadTab_Home",
        "Dashboard"
    },
    "CommandName" : "Update Global Settings"
}

I’m trying to store it in this class, but I am not sure how to handle the embedded Tabs object. There may be an arbitrary number of tabs greater than 0 (so 1+, the first one’s key always being RadTab_Home). Tabs shouldn’t be a string[]. I want it to be a Dictionary<string, string>, but I am unsure how to express that.

[DataContract]
public class GlobalSettingsJSON
{
    private static readonly ILog Logger = 
        LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    public GlobalSettingsJSON() { }

    public GlobalSettingsJSON(string commandName, string autoRefreshEnabled, 
        string autoRefreshInterval, string autoCycleEnabled, 
        string autoCycleInterval, Dictionary<string, string> tabs)
    {
        Logger.InfoFormat("Command Name: {0}, DockID: {1}, " +
            "AutoRefreshEnabled: {2}, AutoRefreshInterval: {3}, " +
            "AutoCycleEnabled: {4}, AutoCycleInterval: {5}",
            commandName, autoRefreshEnabled, autoRefreshInterval, 
            autoCycleEnabled, autoCycleInterval);

        CommandName = commandName;
        AutoRefreshEnabled = autoRefreshEnabled;
        AutoRefreshInterval = autoRefreshInterval;
        AutoCycleEnabled = autoCycleEnabled;
        AutoCycleInterval = autoCycleInterval;
        Tabs = tabs;
    }

    [DataMember(Name = "CommandName")]
    public string CommandName { get; set; }

    [DataMember(Name = "AutoRefreshEnabled")]
    public string AutoRefreshEnabled { get; set; }

    [DataMember(Name = "AutoRefreshInterval")]
    public string AutoRefreshInterval { get; set; }

    [DataMember(Name = "AutoCycleEnabled")]
    public string AutoCycleEnabled { get; set; }

    [DataMember(Name = "AutoCycleInterval")]
    public string AutoCycleInterval { get; set; }

    [DataMember(Name = "Tabs")]
    public Dictionary<string, string> Tabs { get; set; }
}

EDIT: Tabs does not return any data now, but no error is thrown.
EDIT: DataContractJsonSerializer does not support deserializing to a dictionary. JSON.net, however, does!
EDIT: Code worked perfectly using Newtonsoft’s JSON deserializer.

  • 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-23T00:23:00+00:00Added an answer on May 23, 2026 at 12:23 am

    If you want the Tabs property to be a Dictionary<string, string> then your representation in JSON is incorrect. Currently, you have:

    "Tabs" : [
        "RadTab_Home",
        "Dashboard"
    ],
    

    And it should be a string[]. If you want a mapping (i.e. Dictionary<string, string>), then you need a key to associate with the values, and therefore, a different representation in JSON:

    "Tabs" : [
        { "key1" : "RadTab_Home" },
        { "key2" : "Dashboard" }
    ],
    

    With this, you can definitely create a Dictionary<string, string>, as you would have a key to associate with the values. The key would be to create a class, like so:

    // NOTE: You can use POCO DataContract serialization for this type.
    [DataContract]
    public class Pair
    {
        [DataMember]
        public string Key { get; set; }
    
        [DataMember]
        public string Value { get; set; }
    }
    

    And then define your Tabs property like so:

    [DataMember]
    public Pair[] Tabs { get; set; }
    

    Which you can easily convert to a Dictionary<string, string> using LINQ:

    // Deserialized instance.
    MyClass instance = ...;
    
    // Map
    IDictionary<string, string> tabsMap = instance.Tabs.
        ToDictionary(p => p.Key, p => p.Value);
    

    You could add it as a method on your class, but that’s a design decision for you to make (I didn’t add it to the class because I assume this is a data-transfer object).

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

Sidebar

Related Questions

I have this JSON string: { success:true,user_id:309,id:309,sessId:false,email:null,name:Mai Van Quan,username:quanmv,role:Reseller Admin,messages:,org_name:null,microPayNumber:4949,microPayWord:neocam,mobile:null,permissions:{ADD_CAMERA:true, REMOVE_CAMERA:true, EDIT_CAM_GENERAL:true, ACCESS_CAM_TECHNICAL:true, EDIT_CAM_PKG:true,
I have this JSON string: { widgets:[ {column1:[ {weight:1, bID:1, hideMe:false, collapse:false, titleOf:Test 1,
I have this json data: [ {ID:1,name:google,IP:69.5.33.22,active:true}, {ID:2,name:bing,IP:70.5.232.33,active:false} ] I want to get the
I have this JSON (which validates according to JSONLint ): [ { "BugCount":"2", "BugTitle":"C:\\INETPUB\\WWWROOT\\CLUBREADY2\\TRAINERS\\../Connections/LTC.asp",
I have this code: $coder = JSON::XS->new->utf8->pretty->allow_nonref; %perl = $coder->decode ($json); When I write
I have this swf (flash) file that provides the json that needs to be
I have a web service that queries data from this json file, but I
I have a JSON data like this: { hello: { first:firstvalue, second:secondvalue }, hello2:
I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
I have some JSON returned to the browser like this product: { Title: School

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.