首页 > 解决方案 > 如何从 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);
      })
} 

标签: javascriptjsonreact-native

解决方案


在这里试试这个。

let path = responseJson.records[0].path;

删除正斜杠\

path = path.replace("\\","");

推荐阅读