JSON解析错误:无法识别的令牌“ <”-React Native

   signIn = () => { 
    //post data to express backend
    fetch('http://......./api/v1/auth', {
        method: 'POST',
        header: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
              body: `login=${this.state.login}&password=${this.state.password}`
    })

    .then((response) => response.json())
    .then((res) => {

      if (res.success === true) {
          this.props.navigation.navigate('Authorized')
      } else {
          alert(res)
      }
    })
    .done();
}

使用localhost:3000时,我不断收到此类错误,也出现网络失败错误

吉夫

添加try catch似乎响应是text/html格式。

signIn = () => { 
//post data to express backend
fetch('http://......./api/v1/auth', {
    method: 'POST',
    header: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
          body: `login=${this.state.login}&password=${this.state.password}`
})

.then(async (response) => {
  let res;
  try {
    res = await response.clone().json();
  } catch (e) {
    res = await response.text();
  }
  return res;
})
.then((res) => {

  if (res.success === true) {
      this.props.navigation.navigate('Authorized')
  } else {
      alert(res)
  }
})
.done();

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类常见问题

React Native:无法捕获引发的错误

来自分类Dev

React Native:创建组件错误

来自分类Dev

React Native:包解析错误

来自分类Dev

错误:找不到模块“ react-native-web” /未找到模块:错误:无法解析模块“ react-native-web”

来自分类Dev

React Native:无法解析模块fs

来自分类Dev

无法解析模块“ react-native-reanimated”

来自分类Dev

react-native无法解析模块'warnOnce'

来自分类Dev

React-native-reanimated:无法解析“ ./useValue”

来自分类Dev

JSON解析错误:无法识别的令牌“!” -哨兵发现错误

来自分类Dev

React Native错误:“变量”是只读的

来自分类Dev

react-native macOS:发送到实例的RCTViewManager回调无法识别的选择器

来自分类Dev

React Native:无法捕获引发的错误

来自分类Dev

React Native无法解析模块

来自分类Dev

React Native Navigator意外令牌

来自分类Dev

react-native:解析错误:意外的令牌<

来自分类Dev

React Native fetch,意外的令牌

来自分类Dev

React Native 中的 SDK 错误

来自分类Dev

React Native 与 Redux - 意外令牌

来自分类Dev

React Native:意外的令牌

来自分类Dev

AsyncStorage - 错误(React Native)

来自分类Dev

在 React Native 中无法识别 Lodash _.reduce

来自分类Dev

React Native API json 解析数据错误:未处理的承诺拒绝:SyntaxError:JSON 解析错误:无法识别的令牌“<”

来自分类Dev

React Native 错误“无法解析模块‘react-native’”

来自分类Dev

反应原生 JSON 解析错误:无法识别的令牌“<”

来自分类Dev

React Native Image 无法解析模块

来自分类Dev

React Native 错误:无法解析模块`./index`

来自分类Dev

React Native SectionList 渲染错误

来自分类Dev

React Native Paper - 无法识别的字体系列“材料图标”

来自分类Dev

React Native - PhaseScriptExecution 错误

Related 相关文章

  1. 1

    React Native:无法捕获引发的错误

  2. 2

    React Native:创建组件错误

  3. 3

    React Native:包解析错误

  4. 4

    错误:找不到模块“ react-native-web” /未找到模块:错误:无法解析模块“ react-native-web”

  5. 5

    React Native:无法解析模块fs

  6. 6

    无法解析模块“ react-native-reanimated”

  7. 7

    react-native无法解析模块'warnOnce'

  8. 8

    React-native-reanimated:无法解析“ ./useValue”

  9. 9

    JSON解析错误:无法识别的令牌“!” -哨兵发现错误

  10. 10

    React Native错误:“变量”是只读的

  11. 11

    react-native macOS:发送到实例的RCTViewManager回调无法识别的选择器

  12. 12

    React Native:无法捕获引发的错误

  13. 13

    React Native无法解析模块

  14. 14

    React Native Navigator意外令牌

  15. 15

    react-native:解析错误:意外的令牌<

  16. 16

    React Native fetch,意外的令牌

  17. 17

    React Native 中的 SDK 错误

  18. 18

    React Native 与 Redux - 意外令牌

  19. 19

    React Native:意外的令牌

  20. 20

    AsyncStorage - 错误(React Native)

  21. 21

    在 React Native 中无法识别 Lodash _.reduce

  22. 22

    React Native API json 解析数据错误:未处理的承诺拒绝:SyntaxError:JSON 解析错误:无法识别的令牌“<”

  23. 23

    React Native 错误“无法解析模块‘react-native’”

  24. 24

    反应原生 JSON 解析错误:无法识别的令牌“<”

  25. 25

    React Native Image 无法解析模块

  26. 26

    React Native 错误:无法解析模块`./index`

  27. 27

    React Native SectionList 渲染错误

  28. 28

    React Native Paper - 无法识别的字体系列“材料图标”

  29. 29

    React Native - PhaseScriptExecution 错误

热门标签

归档