Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

jquery - Remove Backslashes from Json Data in JavaScript

Remove Backslashes from JSON Data in JavaScript or jQuery

var str = "{"data":"{
 "taskNames" : [
 "01 Jan",
 "02 Jan",
 "03 Jan",
 "04 Jan",
 "05 Jan",
 "06 Jan",
 "07 Jan",
 "08 Jan",
 "09 Jan",
 "10 Jan",
 "11 Jan",
 "12 Jan",
 "13 Jan",
 "14 Jan",
 "15 Jan",
 "16 Jan",
 "17 Jan",
 "18 Jan",
 "19 Jan",
 "20 Jan",
 "21 Jan",
 "22 Jan",
 "23 Jan",
 "24 Jan",
 "25 Jan",
 "26 Jan",
 "27 Jan"]}

var finalData = str.replace("", "");

but this does not work for me. Any help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your string is invalid, but assuming it was valid, you'd have to do:

var finalData = str.replace(/\/g, "");

When you want to replace all the occurences with .replace, the first parameter must be a regex, if you supply a string, only the first occurrence will be replaced, that's why your replace wouldn't work.

Cheers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...