-1

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

2
  • 4
    I'm pretty sure it's because you try to parse something that is not JSON, but a string beginning with <, so XML data (HTML probably). Try to put a console.log(response); right before response.json(); Commented Mar 6, 2019 at 9:52
  • 6
    Possible duplicate of JSON Parse error: Unrecognized token'<' - react-native Commented Mar 6, 2019 at 9:58

1 Answer 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()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.