如果需要将API返回的对象转换成字符串,可以使用JSON.stringify()方法。示例如下:
fetch('https://example.com/api') .then(response => response.json()) .then(data => { // 对象转换成字符串 const stringData = JSON.stringify(data); console.log(stringData); }) .catch(error => console.error(error));
上一篇:API返回的是对象而不是数组。