'JSON Parse error: Unrecognized token '<' React native
Code so far :
fetch('http:/example.com',{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
Id: this.state.TextInputId
})
}).then((response) => response.json())
.then((responseJson) => {
Snackbar.show({
title: responseJson,
duration: Snackbar.LENGTH_SHORT,
});
}).catch((error) => {
console.error(error);
})
this.props.navigation.navigate('Home')
Produces the error: Parse error: Unrecognized token '<' React native
Solution 1:[1]
This is not a issue related to react-native but related to your response. You're getting something like '<' in response which cannot be converted to JSON. Try with response.text()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Akib Shaikh |
