Search code examples
javascriptbackslashstringify

Stringifying stringified data string


I try to stringifying options values of a select element. Loop over options works fine. Values of options are stringified strings that taken from some forms data. So when I try to stringify all options values into one string, JSON.stringify adds backslashes just in front of the double quotes. If I post this stringified stringfy string, is it a healthy method to send with post.

second stringifier function below:

function secimleriDerle(secimID){
    var sD = nY(secimID);
    var sDizisi = [];

    for (xi = 0,xlen = sD.options.length; xi < xlen; xi++) {
        sDizisi.push(sD.options[xi].value);
    }

    return JSON.stringify(sDizisi); 
}

console log that second stringifier function returns:

["0","[{\"bankaID\":\"46\",\"makbuzNO\":\"asdasd\",
 \"makbuzTARIHI\":\"12/12/2501\",\"ihracaatYapilacakUlkeID\":\"2\",
 \"ilacIhracADI\":\"asdasd\",\"makbuzTUTAR\":\"202,06\",
 \"makbuzTipDetayDEGERİ\":\"9\"}]"]

Solution

  • \ is an escape character used by parsers to differentiate between the end of the string quote & a quote in between the string....

    So "\"" simply represents a one character string with value : "

    Similarly "\\" represents a one character string with value : \

    It has been a standard way to use an escape sequences for ages & is obviously healthy.