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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:34:46+00:00 2026-06-01T23:34:46+00:00

For deserialising a json object, I had to define a parent class that would

  • 0

For deserialising a json object, I had to define a parent class that would contain an object or an array of objects for the child class. It has to be an object if an object was retrieved, or an array of objects if an array was retrieved from the json.

JSON array object

{"y":{"x":[{"data":28}, {"data":56}, {"data":89}]}}

JSON object

{"y":{"x":{"data":28}}}

y is receiving x at a time, and x[] at another time. There is no such condition to determine whether y would recieve an array or an object.

Hence for determining whether I received an array or not, I am checking the IsArray() condition.

I tried

class Y
{
   public X x { get { return System.IsArray() ? new X() : new x[] }; set; }
}

class X
{
   public int data { get; set; }
}
  1. It isnt working.
  2. System.IsArray() isn’t being recognised??
  • 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-01T23:34:47+00:00Added an answer on June 1, 2026 at 11:34 pm

    First off, an array is an object. That’s a good thing, since it allows these functions to work (both assume using System;):

    bool IsArray(object o) { return o is Array; }
    bool IsArray(object o) { return o.GetType().IsArray; }
    

    Second, if you want a property whose type can be either X or X[], the property’s type needs to be object:

    class Y             
    {
       private object _x;
       public object x {
           get { return _x; }
           set
           {
               if (value.GetType != typeof(X) && value.GetType != typeof(X[]))
                   throw new ArgumentException("value");
               _x = value;
           }
       }
    }
    

    This somewhat ignores the advantage of static typing, as you’re using object and checking types at run time. It would really be much simpler to define the property as an array, even for those cases where there’s only one value. In such cases, it would be an array whose length is 1.

    • 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.
Suppose I have a json object that looks like: { id: 1, name: john
I am using an API that outputs JSON objects with many attributes including sub-objects.
I would like create a web service in ASP.Net 2.0 that will supports JSON.
In the following Jackson/Java code that serializes objects into JSON, I am getting this:
I have a class that needs to be deserialized from JSON using Jackson. The
I get a json that has field field. If the field has data, then
For deserializing json with unknown field into an object there's @JsonAnySetter. But what if
Im using JSON.NET do deserlaize an object, but i cant get it to work
Hey, I am having a problem deserializing base64 json back into the .net object

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.