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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:18:01+00:00 2026-06-13T23:18:01+00:00

I’m trying to deserialize the following JSON response: [{pollid:1, question:This is a test, start:2011-06-28,

  • 0

I’m trying to deserialize the following JSON response:

[{"pollid":"1", "question":"This is a test", "start":"2011-06-28", "end":"2012-03-21", "category":"Roads", "0":"Yes", "1":"No"} … ]

A problem arises, however, in the fact that the number of parameters following “category” can vary from 0 to 10. Meaning all the following are possible JSON responses:

[{"pollid":"1", "question":"This is a test", "start":"2011-06-28", "end":"2012-03-21", "category":"Roads"} … ]
[{"pollid":"1", "question":"This is a test", "start":"2011-06-28", "end":"2012-03-21", "category":"Roads", "0":"Yes", "1":"No"} … ]
[{"pollid":"1", "question":"This is a test", "start":"2011-06-28", "end":"2012-03-21", "category":"Roads", "0":"Bad", "1":"OK", "2":"Good", "3":"Very good"} … ]

I’m deserializing responses to objects of the following form:

class Poll
    {
        public int pollid { get; set; }
        public string question { get; set; }
        public DateTime start { get; set; }
        public DateTime end { get; set; }
        public string category { get; set; }

        [JsonProperty("0")]
        public string polloption0 { get; set; }
        [JsonProperty("1")]
        public string polloption1 { get; set; }
        [JsonProperty("2")]
        public string polloption2 { get; set; }
        [JsonProperty("3")]
        public string polloption3 { get; set; }
        [JsonProperty("4")]
        public string polloption4 { get; set; }
        [JsonProperty("5")]
        public string polloption5 { get; set; }
        [JsonProperty("6")]
        public string polloption6 { get; set; }
        [JsonProperty("7")]
        public string polloption7 { get; set; }
        [JsonProperty("8")]
        public string polloption8 { get; set; }
        [JsonProperty("9")]
        public string polloption9 { get; set; }
    }

My questions is: Is there perhaps a better way to handle the storing of a varying number of parameters? Having 10 class properties which may or may not be used (depending on the response) seems like such a “hack”.

Any help would be truly appreciated!

Many thanks,
Ted

  • 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-13T23:18:01+00:00Added an answer on June 13, 2026 at 11:18 pm

    You can either hold the variable number of properties in and Array

    Have something like

    List<string> ();
    

    where you put all of polloption1, polloption2 …

    Or you could deserialize the json to a dynamic type

    dynamic d = JObject.Parse(json);
    

    And access the properties which you know exist

    d.pollid, d.start, d.category ... 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And

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.