javascript - 如何从 json 响应中删除 \
问题描述
如何从 responseJson 的路径值中删除 \
{"records": [{
"id":"1",
"title":"React Native",
"description":"Complete React Native course for advanced",
"instructor":"john",
"chapter":"15",
"assignment":"15",
"fees":"799",
"course":"SampleVideo_1280x720_5mb.mp4",
"thumbnail":"158347549716062111655e61eb296f7fd.jpg",
"path":"http:\/\/localhost:8080\/coursePHP\/upload\/158347549716062111655e61eb296f7fd.jpg"
}]}
这是我得到的 json 数据,我需要路径 fetchData(){
return fetch('http://192.168.0.104:8080/api/product/displayCourse.php',{
method: 'POST',
headers: {'Accept': 'application/json','Content-Type': 'application/json'},
})
.then((response) => response.json() )
.then( (responseJson) => {
this.setState({
dataSource: responseJson.records
});
//dataurl = JSON.parse(this.responseJson.records.thumbnail);
})
.catch((error) => {
console.error(error.message);
})
}
解决方案
在这里试试这个。
let path = responseJson.records[0].path;
删除正斜杠\
path = path.replace("\\","");
推荐阅读
- javascript - javascript中的window.focus()
- ros - Rviz:如何通过代码设置 TopDownOrtho 视图的 X、Y
- sql - 如何在 2 列上旋转
- php - LEFT JOIN 每次都为空
- c++ - std::stable_sort 与 std::sort
- jquery - 使 Select2 药盒控件更易于访问且合规并需要反馈(带上您的屏幕阅读器)
- javascript - 将数据发送到后端 submit() 不是函数
- oracle - Oracle 7 DB 文件是否与更高版本兼容?甲骨文 9 还是 10G?
- ios - 在 UserDefaults 中编辑结构而不会丢失数据 Swift
- ansible - 无法通过 ssh 连接到主机:共享连接到
关闭