JSON 解析错误:无法识别的令牌'<'- 反应原生 [英] JSON Parse error: Unrecognized token'<' - react-native

查看:110
本文介绍了JSON 解析错误:无法识别的令牌'<'- 反应原生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON Parse error: Unrecognized token'<'" 在点击 api 时显示错误.代码附在下面注意*:响应采用 JSON 格式.

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

fetch("http:/example.com", {method: "POST",
  body: JSON.stringify(
    {
      uname: uname,
      password: password      
    }
  )
})
.then((response) => response.json())
.then((responseData) => {
  AlertIOS.alert(
      "POST Response",
      "Response Body -> " + JSON.stringify(responseData.body)
  )
}).done();
       this.props.navigation.navigate("Home")
   };

请帮忙.谢谢,

推荐答案

终于下面的代码起作用了.问题出在 Body 参数上.

Finally The below code worked. The problem was with Body parameters.

fetch("http:/example.com", {method: "POST",
  body: "uname=value1&password=value2" // <-- Post parameters        
})
.then((responseData) => {
  AlertIOS.alert(
      "POST Response",
      "Response Body -> " + JSON.stringify(responseData.body)
  )
}).done();
       this.props.navigation.navigate("Home")
};

这篇关于JSON 解析错误:无法识别的令牌'&lt;'- 反应原生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆