I am using react native (with expo) and in the app I am trying to get some data from various APIs. For all APIs it works fine and I get the data but for 1 API it gives the error: [SyntaxError: JSON Parse error: Unexpected character: ]]
.
This is my fetch request function:
export async function fetchData(url) {
const response = await fetch(url);
const data = await response.json();
return data;
}
and this is how I am using it in one of the pages:
useEffect(() => {
const getData = async () => {
if(!noData) {
const url = <API here> + ".json";
console.log(url);
try {
let data = await fetchData(url);
setStartList(data);
} catch(err) {
console.log("Error is: =================================");
console.log(err);
}
}
}
getData()
}, []);
Now this works for all other api except 1 of the apis. The API works perfectly when I put it in the browser and postman but just doesn’t work in the code.