JSON Parse error: Unrecognized token'<' - react-native

前端 未结 10 1639
执笔经年
执笔经年 2020-12-09 11:21

\"JSON Parse error: Unrecognized token\'<\'\" Error is showing while hitting the api. Code is attached below Note* : Response is in the JSON format.

10条回答
  •  悲哀的现实
    2020-12-09 12:02

    You can try by adding the headers to your fetch api, as it posts your record to your url.

    var dataObj = {}
    dataObj.uname = uname,
    dataObj.password = password
    
    fetch("http:/example.com", {
      method: 'post',
      headers: {
        'Accept': 'application/json, text/plain, */*',  // It can be used to overcome cors errors
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(dataObj)
    })
    .then((response) => response.json())
    .then((responseData) => {
      AlertIOS.alert(
          "POST Response",
          "Response Body -> " + JSON.stringify(responseData.body)
      )
    }).done();
        this.props.navigation.navigate("Home")
    };
    

提交回复
热议问题