admin管理员组文章数量:1400128
I run the following
let res = e.target.result.split('\n').map(line => line.split(','));
var myData = $("#dvCSV").text(JSON.stringify(res, null, ' '));
myData = myData.replace("\r", " ");
$("#dvCSV").append(myData);
But I still get \r in the output
[
[
"New York",
"Employee",
"20\r"
],
[
"Singapore",
"Employee",
"15"
]
I run the following
let res = e.target.result.split('\n').map(line => line.split(','));
var myData = $("#dvCSV").text(JSON.stringify(res, null, ' '));
myData = myData.replace("\r", " ");
$("#dvCSV").append(myData);
But I still get \r in the output
[
[
"New York",
"Employee",
"20\r"
],
[
"Singapore",
"Employee",
"15"
]
Share
Improve this question
edited Mar 31, 2018 at 14:05
rob.m
asked Mar 31, 2018 at 13:52
rob.mrob.m
10.6k21 gold badges88 silver badges175 bronze badges
3
- You're using both "\r" and "/r" in your question, "\r" has special meaning (escape for a return character) which one do you really mean? It appears you're trying to remove the "\r" strings from the JSON output but it's not clear from your question. – ellipse-of-uncertainty Commented Mar 31, 2018 at 14:03
-
split('\r\n')
in first line – chuck911 Commented Mar 31, 2018 at 14:05 - @hyphenthis yup, updated thanks. – rob.m Commented Mar 31, 2018 at 14:05
3 Answers
Reset to default 4You need to escape the backslash, and do the replace at the stringify
, where it is a string
JSON.stringify(res, null, ' ').replace("\\r", " ");
Stack snippet sample
var res = [
[
"New York",
"Employee",
"20\r"
],
[
"Singapore",
"Employee",
"15"
]
];
console.log(JSON.stringify(res, null, ' ').replace("\\r", " ") )
replace method only removes first instance. in your case, only first instance of "\r"
Use JSON.parse and stringify together, like
JSON.parse(JSON.stringify(res));
本文标签: javascriptHow to remove r from jsonStack Overflow
版权声明:本文标题:javascript - How to remove r from json? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744139287a2592544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论