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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:34:21+00:00 2026-06-07T20:34:21+00:00

Hi Am trying to parse a json Object with Help of C# DataContractJsonSerializer And

  • 0

Hi Am trying to parse a json Object with Help of C# DataContractJsonSerializer And this is what json may look like

{“user_id”:”121″,”Q1″:”question 1″,”Q2″:”question 2″,”Q3″:”question 3″}

And Number of question can be 200- 500,
So I dont want to make a DataContract with 500 Variables to parse this Json, So I was thinking if there is a way where i can call the constructor or something for this class object with a number parameter like this if there are Q1 – Q30 in jSon

Objectparse new_object = new Objectparse(30);

Which will create variables Q1 to Q30 at runtime? and parse the Json

  • 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-06-07T20:34:23+00:00Added an answer on June 7, 2026 at 8:34 pm

    You could use JavaScriptSerializer:

    var json = @"{""user_id"":""121"",""Q1"":""question 1"",""Q2"":""question 2"",""Q3"":""question 3""}";
    var serializer = new JavaScriptSerializer();
    dynamic result = serializer.DeserializeObject(json);
    Console.WriteLine(result["Q1"]);
    Console.WriteLine(result["Q2"]);
    ...
    

    and if you are using an older version of .NET than 4.0 and cannot use the dynamic feature you could do this:

    var json = @"{""user_id"":""121"",""Q1"":""question 1"",""Q2"":""question 2"",""Q3"":""question 3""}";
    var serializer = new JavaScriptSerializer();
    var result = (IDictionary<string, object>)serializer.DeserializeObject(json);
    Console.WriteLine(result["Q1"]);
    Console.WriteLine(result["Q2"]);
    ...
    

    But let me point out that this is an extremely poor JSON design. The person that designed this class was probably not aware of javascript arrays:

    {
        "user_id": "121",
        "questions": [
            {
                "key": "Q1",
                "value": "question 1"
            },
            {
                "key": "Q2",
                "value": "question 2"
            },
            {
                "key": "Q3",
                "value": "question 3"
            }
        ]
    }
    

    Which could now be serialized into a strongly typed object containing a collections of questions.

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

Sidebar

Related Questions

I'm trying to parse a JSON object, part of which looks like this: {
I'm trying to parse this JSOn with multiple entries of node tag: { nodes:
I am trying to parse some JSON on the Windows Phone with DataContractJsonSerializer .
Im trying to parse an JSON response string to my class objects.. I can't
I am trying to parse a json object using gson in Android application ,the
I am trying to parse the JSON at this URL: http://maps.googleapis.com/maps/api/geocode/json?address=canada&sensor=false in Objective-C. I'm
I have a json string like this: http://pastebin.com/ckUZadwL I'm trying to use gson to
I'm trying to parse JSON string using Boost Spirit store JSON object into recursive
I'm trying to parse some JSON object strings that I'm getting using gson-1.6.jar I
I'm trying to parse a very simple json object with 1 value. (ocUnit test

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.