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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:26:08+00:00 2026-06-13T10:26:08+00:00

Deserializing a small, fixed size, fixed structure, with fixed field names, JSON string is

  • 0

Deserializing a small, fixed size, fixed structure, with fixed field names, JSON string is easy: Just define a class that contains all the fields (with correct types and names, all known at compile time).

Deserializing a variable-size of repeating nested pairs, is somewhat more challenging but can be done with the help of a List<> inside the class.

But what do I do when the name of the fields are unknown at compile time? e.g.:

{
   "container":{
      "GD01AB491103":{
         "field_id1":11,
         "field_id2":12,
         "field_id3":13,
         "field_id4":"fourteen"
      },
      "DC01AB491103":{
         "field_id1":21,
         "field_id2":22,
         "field_id3":23,
         "field_id4":"twenty four"
      },
      "GH01AB451101":{
         "field_id1":31,
         "field_id2":32,
         "field_id3":33,
         "field_id4":"thirty four"
      }
      .
      .
      .
   },
   "terminator"
}

How to deserialize such a string?

(preferably with .NET’s JavaScriptSerializer but if it’s too weak/incapable, I might need to resort to something else)

Edit: To clarify the nature of the challenge: In the example above, in order to define a class:

public class ??????
{
    public int field_id1  {get;set;}
    public int field_id2  {get;set;}
    public int field_id3  {get;set;}
    public string field_id4 {get;set;}
}

I need to query the JSON string first, then at runtime build classes (reflection?) with these variable-name class objects in it? Looks too cumbersome… Perhaps there is a saner way?

Or maybe the class/field names are irrelevant to .NET’s JavaScriptSerializer and all matters is the type? (and correct structure of course)

  • 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-13T10:26:09+00:00Added an answer on June 13, 2026 at 10:26 am

    You can do this probably more simply than you think.. your ?????? class can be anything..

    public class GenericObject
    {
        public int field_id1  {get;set;}
        public int field_id2  {get;set;}
        public int field_id3  {get;set;}
        public string field_id4 {get;set;}
    }
    

    and then deserialize the root of the object graph into an object that contains a Dictionary<string,GenericObject>…

    public class SomeContainer
    {
        public Dictionary<string,GenericObject> container {get;set;}
    }
    

    you can then loop over the values of the dictionary if you don’t care about the names of the keys.

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

Sidebar

Related Questions

I have a Java class MyPojo that I am interested in deserializing from JSON.
I am serializing some C structure to string and than deserializing it with strtok()
After Deserializing a file with just one record It seems that it's in an
For deserializing json with unknown field into an object there's @JsonAnySetter. But what if
I'm deserializing some properties to a Dictionary<string, object> . When I deserialize some json,
I'm having trouble deserializing a ruby class that I wrote to YAML. Where I
I am deserializing an object from a file that is 350KB in size, and
I'm using the jackson library for serializing/deserializing to/from JSON. I need that this JSON
I am really struggling deserializing a PHP json encoded string in ASP.NET. I am
I'm having a problem with deserializing a json string to a dictionary. I'm using

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.