samedi 26 décembre 2015

Escaping special characters in json

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);

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

Aucun commentaire:

Enregistrer un commentaire