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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:10:34+00:00 2026-05-28T02:10:34+00:00

I’m implementing a method that is returning a json result like: public JsonResult MethodName(Guid

  • 0

I’m implementing a method that is returning a json result like:

public JsonResult MethodName(Guid key){
    var result = ApiHelper.GetData(key); //Data is stored in db as varchar with åäö
    return Json(new { success = true, data = result },"application/json", Encoding.Unicode, JsonRequestBehavior.AllowGet );
}

The displayed result:

{"success":true,"data":[{"Title":"Here could be characters like åäö","Link":"http://www.url.com/test",...},

But I would like to display it like:

{"success":true,"data":[{"Title":"Here could be characters like \u00e5\u00e4\u00f6","Link":"http:\/\/www.url.com\/test",...},

How can I accomplish this?
Can I convert it, parse it or change the responseEncoding in web.config to get it to display unicode characters?

  • 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-05-28T02:10:34+00:00Added an answer on May 28, 2026 at 2:10 am

    There is no need for escaping if the client is a web browser, or any other client that handles http correctly, as long as your server correctly tells the client about content type and content encoding, and the encoding you select supports the codepoints in the outgoing data.

    If the client does not behave correctly, and it really needs the strings to be escaped like that, you will have to write your own ActionResult class and do the escaping yourself. Inherit from JsonResult to start with, and use reflection to create the JSON document as you like it.

    It’s a chore!

    EDIT: This will get you started

    public class MyController : Controller {
        public JsonResult MethodName(Guid key){
            var result = ApiHelper.GetData(key);
            return new EscapedJsonResult(result);
        }
    }
    
    public class EscapedJsonResult<T> : JsonResult {
        public EscapedJsonResult(T data) {
            this.Data = data;
            this.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
        }
    
        public override ExecuteResult(ControllerContext context) {
            var response = context.HttpContext.Response;
    
            response.ContentType = "application/json";
            response.ContentEncoding = Encoding.UTF8;
    
            var output = new StreamWriter(response.OutputStream);
    
            // TODO: Do some reflection magic to go through all properties
            // of the this.Data property and write JSON to the output stream
            // using the StreamWriter
    
            // You need to handle arrays, objects, possibly dictionaries, numbers,
            // booleans, dates and strings, and possibly some other stuff... All
            // by your self!
        }
    
        // Finds non-ascii and double quotes
        private static Regex nonAsciiCodepoints =
            new Regex(@"[""]|[^\x20-\x7f]");
    
        // Call this for encoding string values
        private static string encodeStringValue(string value) {
            return nonAsciiCodepoints.Replace(value, encodeSingleChar);
        }
    
        // Encodes a single character - gets called by Regex.Replace
        private static string encodeSingleChar(Match match) {
            return "\\u" + char.ConvertToUtf32(match.Value, 0).ToString("x4");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to count the length of a string with PHP. The string
I have a French site that I want to parse, but am running into
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.