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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:32:16+00:00 2026-06-07T06:32:16+00:00

I am using JSON web-service. On any JSON request web-service could respond via Error

  • 0

I am using JSON web-service. On any JSON request web-service could respond via Error type JSON or Response type. For example:

{
    "response": "register",
    "error": {
        "@c" : "error",
        "code": "USER_EXISTS",
        "message": ""
    }
}

or

{
    "response": "register",
    "register": {
        "session": {
            "@c" : "session",
            "userId": "18",
            "sessionId": "ASFT23WETT234QQW"
        }
    }
}

Any response I trying to deserialize to type, which is related to request. For example, RegisterResponse when request is RegisterRequest.

If response is Error type response, code

JsonConvert.DeserializeObject<RegisterResponse> (jsonResponse);

created RegisterResponse with all empty poperties values.

How to suggest JSON.NET to throw exception if there is some incompatibility with JSON string and target type?

Classes definitions:

public class Response
{
    public string response { get; set; }

    public Response ()
    { }
}


public class Session
{
    public long userId;
    public string sessionId;

    public Session ()
    { }
}

public class RegisterResponse: Response
{
    public Session session { get; set; }

    public RegisterResponse ()
    {
        session = new Session();
    }
}

public class Error
{
    public string code;
    public string message;

    public Error ()
    {
    }
}
  • 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-07T06:32:18+00:00Added an answer on June 7, 2026 at 6:32 am

    This is not directly JSON.NET’s bag because the conversion you gave it is actually completely valid semantically, you just gave it bad data. The best thing to do would simply be to check your data first. Either create an Error class and convert that via

    JsonConvert.DeserializeObject<Error> (jsonResponse);
    

    And then test Error‘s properties to make sure that they are empty the way you’d hope.

    Alternately you could just decode the single Error property you’re looking for to see if it comes back null.

     JObject o = JObject.Parse(jsonResponse);
     string error = (string)o["Error"];
     if(string.IsNullOrEmpty(error) == false)
        // bad things going down
     // if you get here it's all good
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using NSJSONSerialization to parse some JSON from my web service, and I want
I am trying to retrieve a JSON file from a web service using the
I am calling a json web service that sends error messages by setting StatusCode
I'm trying to get ASP.Net to cache the response of a web service request
I'm trying to grab some JSON data from a web service using JSON.Net. The
I am using jquery Get request to retrieve data from a web service. The
I am successfully retrieving JSON data from a web service with GET using Restkit's
I want to create a .NET webservice using C# with JSON. but I've error
I am using spring 3.0 webservices. It produces a json response. I want to
I have a web site with an API which publishes the information using JSON.

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.