【问题标题】:I'm trying to use the json file, but it can't be return data我正在尝试使用 json 文件,但它不能返回数据
【发布时间】:2019-04-14 05:18:05
【问题描述】:

我要使用这个 json
但我收到错误 TypeError: Cannot read property 'aFeeds' of undefined 如何获得价值?

  return  fetch('https://freemusicarchive.org/featured.json'
    )
        .then(respone => respone.json())
       .then(json => console.log(json))
        .then(json=> json.aFeeds.aTracks)
        .catch(err=>console.log(err))

【问题讨论】:

    标签: javascript json reactjs ecmascript-6


    【解决方案1】:

    因为在您的第二个then 中,您没有返回任何内容,因为console.log 没有返回值。如果你想记录它,你必须使用一个函数体和returnjson

    return fetch("https://freemusicarchive.org/featured.json")
        .then(respone => respone.json())
        .then(json => {
            console.log(json);
            return json;
        })
        .then(json => json.aFeeds.aTracks)
        .catch(err => console.log(err));
    

    【讨论】:

      猜你喜欢
      • 2020-04-26
      • 1970-01-01
      • 2019-05-08
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多