i have this string:
JavaScript
x
2
1
"{\'Ovcount\':\'0\',\'S1\':\'LU\',\'S2\':\'NewClientOrMove\',\'memoToDisplay\':\'LU -- New Client or Move\"}";
2
and i want it to become like this:
JavaScript
1
2
1
'{"Ovcount":"0","S1":"LU","S2":"NewClientOrMove","memoToDisplay":"LU -- New Client or Move"}'
2
I tried with stringify and replace and i ended up with
JavaScript
1
2
1
"{'Ovcount':'0','S1':'LU','S2':'NewClientOrMove','memoToDisplay':'LU -- New Client or Move"}"
2
And from here i wanted to replace the single quotation marks '
with double quotation marks "
but when i did, in beginning and ending of the string appeared an extra "
JavaScript
1
2
1
" "{"Ovcount":"0","S1":"LU","S2":"NewClientOrMove","memoToDisplay":"LU -- New Client or Move"} ""
2
Any tips on how to get the correct format?
Advertisement
Answer
JavaScript
1
4
1
var result = "{'Ovcount':'0','S1':'LU','S2':'NewClientOrMove','memoToDisplay':'LU -- New Client or Move"}"
2
.replaceAll("'", '"')
3
.replaceAll('\', '');
4
console.log(result);
this got me what you wanted, it replaces all the single quotes with double quotes, then it removes any back slashes
the result is
‘{“Ovcount”:”0″,”S1″:”LU”,”S2″:”NewClientOrMove”,”memoToDisplay”:”LU — New Client or Move”}’