Home:ALL Converter>Escaping special characters in json

Escaping special characters in json

Ask Time:2015-12-27T02:09:59         Author:Eng Sabreen Saber

Json Formatter

I built Data table in mvc this data table in rendering page i send to it 100 rows after that you can get data by AJAX (see more) in rendering i send data in json string

Code in httpget action

    viewmodelobj.str= (new System.Text.StringBuilder(Newtonsoft.Json.JsonConvert.SerializeObject(viewmodelobj.datalist)).Replace("\\r", "<br/>").Replace("\\t", "").Replace("\\\"", "&quot;").Replace("'", "&#39;").Replace("\\\\", "&#92;").Replace("\\n", "<br/>")).ToString();

and i need to escape special characters because if i send it without escaping those characters data will not displayed

Code in view

var jsobj= JSON.parse(workqueueLoadedData);
        $('#datatableId').DataTable().rows.add(jsobj).draw();

But when i make see more and get data by ajax i didn't have to escape special characters although i use almost the same code Send data by ajax

var jsonResult = Json(new
        {
            data = lisOfWorkQueue
        }, JsonRequestBehavior.AllowGet);
        jsonResult.MaxJsonLength = int.MaxValue;

        return jsonResult;

So do you know why it's working right in ajax without escaping special characters unlike get action ? and is there another way to send json from controller to view in rendering step without escaping special characters , thanks in advance

Author:Eng Sabreen Saber,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34473904/escaping-special-characters-in-json
yy