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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:06:54+00:00 2026-06-03T19:06:54+00:00

I want to directly capture JSON from an external API in a service layer,

  • 0

I want to directly capture JSON from an external API in a service layer, return that to a MVC 4 ApiController, and then output the JSON through that ApiController. I’m basically writing a wrapper around another API service because some other actions have to happen at the same time (authentication, etc). The problem is that the JSON gets converted to a string and is passed around as a string in my C# code. This just adds escape characters to the JSON. Is there anyway I can just pass the JSON object around in my C# code? Details of my implementation are below.

In a service layer, I’m consuming an API that provides JSON via the method below.

return new WebClient().DownloadString(url);

Unfortunately this returns a string. As this API is already returning JSON to me this is problematic because lots of escape characters get added to the string.

The JSON should look something like this

[{"Citation":{"Attachments":[{"AttachedPersonIds":null,..."Type":"Record"}]

But instead it now looks like this

"[{\"Citation\":{\"Attachments\":[{\"AttachedPersonIds\":null,...\"Type\":\"Record\"}]"

After I get this string I return it through a couple of methods to an ApiController (which is setup to return JSON) like this.

public class HintsController : ApiController
{
    public string Get(string treeId, string personId)
    {
        return _hintService.GetHints(treeId, personId);
    }
}

I’ve tried to convert the string to a Literal string and tried serializing the string again. Doing this just adds more escape characters and doesn’t solve the problem. I think the problem is with how I’m consuming the initial call because it’s casting it from JSON to a string. But I don’t know how to avoid this.

Thanks in advance for any ideas.

  • 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-03T19:06:56+00:00Added an answer on June 3, 2026 at 7:06 pm

    Because the controller returns a string, the JSON formatter is serializing the entire string to a JSON string and escaping the embedded quote characters.

    You can do something like this:

    public HttpResponseMessage Get()
    {
        var resp = new HttpResponseMessage()
        {
            Content = new StringContent("{json here...}")
        };
        resp.Content.Headers.ContentType = 
                      new MediaTypeHeaderValue("application/json");
        return resp;
    }
    

    This assumes that you always want to return JSON.

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

Sidebar

Related Questions

I have a huge IQueryable that I want to export directly to Excel for
I want to redirect the output of some Windows program directly to gvim basically
I want to create a Gameboy emulator which runs directly from the exe file,
I want to plot a line from one well-defined point to another and then
I want to directly install my application after dowloading it from android market place
I want to have bookmarkable URLs that the browser can capture and handle. If
I am creating an android application, and I want to directly access another application's
I have a Binary tree for a mathematical expression(infix), i want to convert directly
I want to upload files directly to IIS7 (in this case I am using
I want to run Firefox directly on top of X for a kiosk, but

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.