Код: Выделить всё
const apiUrl = 'http://hermes.hstn.me/api/';
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Accept': 'application/json',
}
});
if(!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const responseData = await response.json();
console.log('responseData: ', responseData);
Код: Выделить всё
{"status":"success","message":"data retrieved successfully","items":[{"id":1,"name":"a"},{"id":2,"name":"b"}]}
Код: Выделить всё
Код: Выделить всё
Error: Uncaught (in promise, id: 0): "SyntaxError: JSON Parse error: Unexpected character:
Подробнее здесь: [url]https://stackoverflow.com/questions/79791509/react-native-fetch-is-returning-an-error-but-the-character-causing-the-error-is[/url]
Мобильная версия