【问题标题】:how to get remove \ from json response如何从 json 响应中删除 \
【发布时间】:2020-03-06 15:35:52
【问题描述】:

如何从 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 数据 我需要路径中的 url 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);
      })
} 

【问题讨论】:

  • 应该是:responseJson.records[0].pathrecords 是一个数组,路径值(包含 URL)在该数组第一个条目的对象中。
  • 我得到了路径值谢谢
  • 但是如何去除前睫毛
  • 如果是 URL,您将希望删除反斜杠,而不是正斜杠!反正你一开始没问这个,但是你可以用字符串替换功能,很简单。你可以在几秒钟内自己google一下。

标签: javascript json react-native


【解决方案1】:

在这里试试这个。

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

删除正斜杠\

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-11
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多