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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:50:38+00:00 2026-05-27T00:50:38+00:00

I’m using JSON.Net to try and deserialize some survey responses from SurveyGizmo. Here’s a

  • 0

I’m using JSON.Net to try and deserialize some survey responses from SurveyGizmo.
Here’s a snapshot of the data I’m reading in:

{"result_ok":true,
"total_count":"44",
"page":1,
"total_pages":1,
"results_per_page":50,
"data":[
        {"id":"1",
        "contact_id":"",
        "status":"Complete",
        "is_test_data":"0",
        "datesubmitted":"2011-11-13 22:26:53",
        "[question(59)]":"11\/12\/2011",
        "[question(60)]":"06:15 pm",
        "[question(62)]":"72",
        "[question(63)]":"One",
        "[question(69), option(10196)]":"10",

I’ve setup a class as far as datesubmitted but I’m not sure how to setup the class to deserialize the questions given that the amount of questions will change? I also need to capture the option if it’s present.

I’m using this code to use the JSON.NET Deserialize function:

Dim responses As Responses = JsonConvert.DeserializeObject(Of Responses)(fcontents)

Classes:

Public Class Responses
    Public Property result_OK As Boolean

    Public Property total_count As Integer

    Public Property page As Integer

    Public Property total_pages As Integer

    Public Property results_per_page As Integer

    Public Overridable Property data As List(Of surveyresponse)
End Class

Public Class SurveyResponse
    Public Property id As Integer

    Public Property status As String

    Public Property datesubmitted As Date
End Class
  • 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-27T00:50:39+00:00Added an answer on May 27, 2026 at 12:50 am

    This trick to support totally crazy mappings is to use JsonConverter and completely replace the parsing for that object, (I apologize for the C#, but I’m no good at VB syntax):

    class Program
    {
        static void Main(string[] args)
        {
            var result = JsonConvert.DeserializeObject<Responses>(TestData);
        }
    
        const string TestData = @"{""result_ok"":true,
    ""total_count"":""44"",
    ""page"":1,
    ""total_pages"":1,
    ""results_per_page"":50,
    ""data"":[
        {""id"":""1"",
        ""contact_id"":"""",
        ""status"":""Complete"",
        ""is_test_data"":""0"",
        ""datesubmitted"":""2011-11-13 22:26:53"",
        ""[question(59)]"":""11\/12\/2011"",
        ""[question(60)]"":""06:15 pm"",
        ""[question(62)]"":""72"",
        ""[question(63)]"":""One"",
        ""[question(69), option(10196)]"":""10"",
    }]}";
    }
    
    [JsonObject]
    class Responses
    {
        public bool result_ok { get; set; }
        public string total_count { get; set; }
        public int page { get; set; }
        public int total_pages { get; set; }
        public int results_per_page { get; set; }
        public SurveyResponse[] Data { get; set; }
    }
    
    [JsonObject]
    // Here is the magic: When you see this type, use this class to read it.
    // If you want, you can also define the JsonConverter by adding it to
    // a JsonSerializer, and parsing with that.
    [JsonConverter(typeof(DataItemConverter))]
    class SurveyResponse
    {
        public string id { get; set; }
        public string contact_id { get; set; }
        public string status { get; set; }
        public string is_test_data { get; set; }
        public DateTime datesubmitted { get; set; }
        public Dictionary<int, string> questions { get; set; }
    }
    
    class DataItemConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof(SurveyResponse);
        }
    
        public override bool CanRead
        {
            get { return true; }
        }
    
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var value = (SurveyResponse)existingValue;
            if (value == null)
            {
                value = new SurveyResponse();
                value.questions = new Dictionary<int, string>()
            }
    
            // Skip opening {
            reader.Read();
    
            while (reader.TokenType == JsonToken.PropertyName)
            {
                var name = reader.Value.ToString();
                reader.Read();
    
                    // Here is where you do your magic
                if (name.StartsWith("[question("))
                {
                    int index = int.Parse(name.Substring(10, name.IndexOf(')') - 10));
                    value.questions[index] = serializer.Deserialize<string>(reader);
                }
                else
                {
                    var property = typeof(SurveyResponse).GetProperty(name);
                    property.SetValue(value, serializer.Deserialize(reader, property.PropertyType), null);
                }
    
                // Skip the , or } if we are at the end
                reader.Read();
            }
    
            return value;
        }
    
        public override bool CanWrite
        {
            get { return false; }
        }
    
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }
    }
    

    Now obviously there’s a lot more you would want to do to get this really robust, but this gives you the basics of how to do it. There are more lightweight alternatives if you simply need to change property names (either JsonPropertyAttribute or overriding DefaultContractResolver.ResolvePropertyName(), but this gives you full control.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... 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.