Shi*_*hew 0 json react-native fetch-api
我用过
const response =await fetch('https://facebook.github.io/react-native/movies.json');
const json= await response.json();
console.log(json.result);
Run Code Online (Sandbox Code Playgroud)
用于打印获取的json数据到控制台,但无法正常工作。如何将获取的数据直接写入控制台。
fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
Run Code Online (Sandbox Code Playgroud)
使用同步/等待的答案(您在问题中使用的答案)
const fetchAndLog = async () => {
const response = await fetch('https://facebook.github.io/react-native/movies.json');
const json = await response.json();
// just log ‘json’
console.log(json);
}
fetchAndLog();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11269 次 |
| 最近记录: |