我想得到的是选择“质量”的“url”值为hd720
组件
componentDidMount() { return fetch('https://you-link.herokuapp.com/?url=https://www.youtube.com/watch?v=YGCLs9Bt_KY') .then((response) => response.json()) .then((responseJson) => { this.setState({ isLoading: false, dataSource: responseJson, videoUrl: responseJson[0].url }, function() { }); }) .catch((error) => { console.error(error); }); }
Json调用
Link
最佳答案
您只需搜索具有匹配条件 ( Using find ) 的 JSON 数组 在这种情况下,“质量”===“hd720”
componentDidMount() {
return fetch('https://you-link.herokuapp.com/?url=https://www.youtube.com/watch?v=YGCLs9Bt_KY')
.then((response) => response.json())
.then((responseJson) => {
let url = responseJson.find(obj => obj.quality === "hd720").url
this.setState({
isLoading: false,
dataSource: responseJson,
videoUrl: url
}, function() {});
})
.catch((error) => {
console.error(error);
});
}
关于javascript - 我如何在 React Native 中从 json 中选择一个特定的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53375754/