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?
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
ActionResultclass and do the escaping yourself. Inherit fromJsonResultto start with, and use reflection to create the JSON document as you like it.It’s a chore!
EDIT: This will get you started