【问题标题】:react native android error SyntaxError: Unexpected token in JSON at position 0react native android error SyntaxError: Unexpected token in JSON at position 0
【发布时间】:2018-07-18 05:26:05
【问题描述】:

错误日志:

blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:55463 Possible Unhandled Promise Rejection (id: 0):
SyntaxError: Unexpected token  in JSON at position 0
SyntaxError: Unexpected token  in JSON at position 0
    at parse (<anonymous>)
    at tryCallOne (blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:21859:14)
    at blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:21960:17
    at blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:8761:21
    at _callTimer (blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:8650:9)
    at _callImmediatesPass (blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:8686:9)
    at Object.callImmediates (blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:8905:14)
    at MessageQueue.__callImmediates (blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:8239:18)
    at blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:8066:18
    at MessageQueue.__guardSafe (blob:http://localhost:8081/d0cb8da3-cbda-4352-940d-9ad7827bfee6:8223:11)

仅在 Android 上存在问题,本机反应。我使用 fetch,方法 post。

示例代码:

fetch(config.server + "/api/districts", {
      method: "POST"
    })
      .then(res => res.json())
      .then(res => {
        this.setState({ districts: res.data });
      });

【问题讨论】:

  • 检查数据是否为合法json
  • @AravindS 数据有效,我在控制台中检查了。
  • 如果删除 .data 会发生什么?

标签: android react-native fetch


【解决方案1】:

这只是后端编码的问题(没有 BOM 的 UTF-8)。

【讨论】:

  • 我也有同样的问题。但它在 ios 中运行良好。解决方案是什么?
猜你喜欢
  • 2022-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-30
  • 2019-08-14
相关资源
最近更新 更多