【发布时间】: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