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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:06:09+00:00 2026-05-26T22:06:09+00:00

The question is similar to Deserializing JSON with unknown fields but I would like

  • 0

The question is similar to Deserializing JSON with unknown fields but I would like to use the built in DataContractJsonSerializer instead.

So I have JSON data like that:

{
"known1": "foo",
"known2": "bar",
"more":{ "unknown12345": { "text": "foo", "label": "bar"},
         "unknown67890": { "text": "foo","label":"bar"}
       }
}

I thought I can do the datacontract like that:

 [DataMember(Name = "known1")]
        public string K1 { get;  set;  }
 [DataMember(Name = "known2")]
        public string K2 { get;  set;  }
 [DataMember(Name = "more")]
        public Dictionary<string,TwoStringMembersClass> More {   get; set;  }

And the TwoStringMembersClass is just this:

 [DataContract(Name = "TwoStringMembersClass ")]
    public class TwoStringMembersClass 
    {
        [DataMember(Name = "text")]
        public string Text { get;  set; }

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

But what seems to work in JSON.Net doesn’t seem to work that easy with the native JSON parser. In ReadObject() I get an ArgumentException, probably because of the Dictionary.

Any idea what’s the best solution how to make this work ?

Thanks in advance.

  • 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-26T22:06:10+00:00Added an answer on May 26, 2026 at 10:06 pm

    The DataContractJsonSerializer does not support deserializing Dictionary<TKey, TValue> from an object notation in JSON. It only supports treating a dictionary as an array. Hence the JSON needed to deserialize into the types you have defined should look like this:-

    {
        "known1": "foo",
        "known2": "bar",
        "more":[{ "Key": "unknown12345", "Value": { "text": "foo", "label": "bar"} },
                { "Key": "unknown67890", "Value": { "text": "foo","label":"bar"} }
               ]
    }
    

    If the schema of the incoming JSON can’t be altered then you are not going to be able to use the DataContractJsonSerializer.

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

Sidebar

Related Questions

Similar question , but for Oracle. Why would I not always want to choose
There are similar question, but not regarding C# libraries I can use in my
I have a question similar to This one . But I want to implement
I have a question similar to this - Does Silverlight xaml support Byte Data
I have a question similar to this question but it is MonoTouch specific. When
I feel like I've read a question similar to this but I can't find
A question similar to Locating bundles by identifier , but different problem: I have
I have a question similar to this one , except with Javascript instead of
I've asked a question similar to this but thought I would ask a more
I have a question similar to this but in the context of L2S. I

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.