© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
10 replies
Pannekoekje

✅ How to deal with different JSON types

I have an API endpoint and depending on the query it can return a list of objects or an object as such:


Query for multiple
{"option": "1", "response":[{"A": "A"}, {"B": "B"}]}
{"option": "1", "response":[{"A": "A"}, {"B": "B"}]}


Query for single
{"option": "1", "response":{"A": "A"}}
{"option": "1", "response":{"A": "A"}}


For now I'm only allowing queries for multiple but would like to support both.
    public class Response
    {
        public string A { get; set; }
        public string B { get; set; }
    }

    public class Root
    {
        public string option { get; set; }
        public List<Response> response { get; set; }
    }
    public class Response
    {
        public string A { get; set; }
        public string B { get; set; }
    }

    public class Root
    {
        public string option { get; set; }
        public List<Response> response { get; set; }
    }


Is there a way to support this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to Deserialize dynamic types from json
C#CC# / help
4mo ago
✅ How do I deal with generic covariance and collections types?
C#CC# / help
3y ago
Json array with multiple types to object
C#CC# / help
3y ago
How to deal with stack overflow error [Answered]
C#CC# / help
4y ago