I'm using fetch
at react-native app powered by expo,
const onStartPress = (level) => {
setIsError(false);
setIsLoading(true);
fetch(
`https://cors-anywhere.herokuapp.com/http://www.cs.utep.edu/cheon/ws/sudoku/new/?size=9?level=${level}`,
{
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
}
)
.then((response) => response.json())
.then((json) => {
if (!json.squares) setIsError(true);
else {
let arr = Array.from({ length: 9 }, () => Array(9).fill(0));
json.squares.forEach((square) => {
let { x, y, value } = square;
arr[x][y] = value;
});
setInitPuzzle(arr);
}
})
.catch((e) => {
console.log(e);
setIsError(true);
});
};
while this code working as expected on web env, at an android device/emulator it gives me (from catch
log)
SyntaxError: Unexpected token M in JSON at position 0
The answeres I found on the web was either about 'Content-Type'
and Accept
(which didn't work for me, as added to my code), or manipulate the android manifest, which is tricky cause I don't want to eject expo.
有什么办法吗?提前致谢 :)