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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:52:07+00:00 2026-06-05T21:52:07+00:00

I have a basic web service that returns the following object as JSON: public

  • 0

I have a basic web service that returns the following object as JSON:

public class GetCustomerResponse
{
  public Guid InteractionId { get; set; }
  public string CustomerInfo { get; set; }
}

The CustomerInfo member is also JSON so the return back to the caller contains escaped JSON, which to be honest is fair enough and to be expected

However, I would like the CustomerInfo JSON to be “embedded” within the response without any escaping. Does anybody know if this is possible and if so how?

The reason for having to deal with CustomerInfo as a string is because this is generated by a sub system that is not based on objects so all I get back is a raw JSON string.

I realised that this could be solved by creating a CustomerInfo class within the service however I would prefer to avoid this as this would be a large class with many members, more importantly it would require the service to be updated if any changes were made.

EDIT : I have accepted the answer from Sergey Kudriavtsev as this works, however in the end I opted for a different solution.

I have added the json.net libraries to the solution and edited my GetCustomer class as follows:

public Newtonsoft.Json.Linq.JObject CustomerInfo { get; set; }

Then in code I have altered the service interface from:

GetCustomerResponse GetCustomer(int customerId)

to:

void GetCustomer(int customerId)

Then in the implementation of the interface I am doing the following

public void GetCustomer(int customerId)
{
  var customerJson = ... code to get json string ...

  var response = new GetCustomerResponse()
  {
    InteractionId = Guid.NewGuid(),
    CustomerInfo = JObject.Parse(customerJson)
  };

  string json = JsonConvert.SerializeObject(response, Formatting.Indented);

  HttpContext.Current.Response.ContentType = "application/json; charset=utf-8";
  HttpContext.Current.Response.Write(json);
}
  • 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-05T21:52:09+00:00Added an answer on June 5, 2026 at 9:52 pm

    I think the most correct way of doing this is creating a separate CustomerInfo class as you described.

    However, if you don’t want to do that then there are at least two alternatives:

    1) Manually serialize your object to JSON, i.e. use something like

    public string SerializeGetCustomer(GetCustomer data)
    {
        return "{\"InteractionId\":\"" + data.InteractionId.ToString() + 
            "\",\"CustomerInfo\":" + data.CustomerInfo + "}";
    }
    

    2) Deserialize CustomerInfo into generic Dictionary<String, Object> (without creating specific class) and then serialize it back as a part of GetCustomer class, i.e.:

    public class GetCustomer
    {
      public Guid InteractionId { get; set; }
      public Dictionary<String, Object> CustomerInfo { get; set; }
      public GetCustomer(Guid interactionId, string customerInfo)
      {
        InteractionId = interactionId;
        CustomerInfo = new JavaScriptSerializer().Deserialize<Dictionary<String,Object>>(customerInfo);
      }
    }
    
    ...
    string result = new JavaScriptSerializer.Serialize(new GetCustomer(interactionId, customerInfo));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic web service running that accesses a database and returns XmlDocuments.
I have the following code in a class that is called from a web
I have a WCF web service, and I want to use Basic authentication. I
I have some basic knowledge about web security that I have gained through years
I have a website that uses basic ASP.Net forms authentication. In the web.config file
Goal: Provide a web service using Visual Basic or C# or .NET that interacts
I have the following class: package lt.vic.valdos.domain.valda; public class Valda implements java.io.Serializable { private
I have made a REST Web service, that works with Visual Studios WCF Test
I have a problem with some basic ajax and asp.net web service. In my
We currently have a SOAP based web service that our in house applications use

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.