asp.net mvc outputting json with backslashes ( escape) despite many attemps to filter

Posted by minus4 on Stack Overflow See other posts from Stack Overflow or by minus4
Published on 2010-04-24T15:45:27Z Indexed on 2010/04/24 15:53 UTC
Read the original article Hit count: 351

i have an asp.net controller that output Json as the results

a section of it is here

returnString += string.Format(@"{{""filename"":""{0}"",""line"":[", file.Filename);

what i get returned is this:

"{\"DPI\":\"66.8213457076566\",\"width\":\"563.341067\",\"editable\":\"True\",\"pricecat\":\"6\",\"numpages\":\"2\",\"height\":\"400\",\"page\":[{\"filename\":\"999_9_1.jpg\",\"line\":[]},{\"filename\":\"999_9_2.jpg\",\"line\":[]}]]"

i have tried to return with the following methods:

return Json(returnString);
return Json(returnString.Replace("\\","");

return Json will serialize my string to a jSon string, this i know but it likes to escape for some reason, how can i get rid of it ????

for info this is how i call it with jQuery:

$.ajax({
    url:"/Products/LoadArtworkToJSon",
    type:"POST",
    dataType: "json",
    async: false,
    data:{prodid: prodid },
    success: function(data){ 
        sessvars.myData = data;
        measurements = sessvars.myData;
        $("#loading").remove();

    //empty the canvas and create a new one with correct data, always start on page 0;
    $("#movements").remove();
    $("#canvas").append("<div id=\"movements\" style=\"width:" + measurements.width + "px; height:" 
            + Math.round(measurements.height) 
            + "px; display:block; border:1px solid black; background:url(/Content/products/" 
            + measurements.page[0].filename + ") no-repeat;\"></div>");

your help is much appreciated

thanks

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about JSON