Javascript I';我试图使用json文件,但它可以';不能返回数据
我是ganna使用这个jsonJavascript I';我试图使用json文件,但它可以';不能返回数据,javascript,json,reactjs,ecmascript-6,Javascript,Json,Reactjs,Ecmascript 6,我是ganna使用这个json 但我得到了错误TypeError:无法读取未定义的属性“aFeeds” 我怎样才能得到这个值 return fetch('https://freemusicarchive.org/featured.json' ) .then(respone => respone.json()) .then(json => console.log(json)) .then(json=> json.aFee
但我得到了错误TypeError:无法读取未定义的属性“aFeeds” 我怎样才能得到这个值
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))
因为在第二个
then
中,您没有返回任何内容,因为console.log
没有返回值。如果要记录它,必须使用函数体并返回json
:
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));