首页 > 解决方案 > [未处理的承诺拒绝:SyntaxError: JSON Parse error: Unrecognized token '']

问题描述

我只想在反应本机错误中映射一个 JSON 数据,但是在用 JSON.parse 解析它之后,我收到错误“[Unhandled promise reject: SyntaxError: JSON Parse error: Unrecognized token '']”。

    axios.get("http://www.upclass.com.hk/api.php?apicall=getcustomer").then((e) => {
          var res = JSON.parse(e.data)
          console.log("New Data =>", res);
          this.setState({
                data: res
                });
    });

这是 JSON 数据

{
"id": "D6C9C876-CDA2-4C27-85BF-276D3035D762",
"fullname": null,
"username": null,
"email": "mohssssin@gmail.com",
"areaid": null,
"aid": null,
"mobile": "123456",
"photoid": null,
"imagepath": null,
"lang": "zh",
"custgroup": "P         ",
"IsVolunteer": null,
"notification": "Y",
"createdate": "2021-03-26 19:05:02.290",
"updatedate": null,
"otherarea": null
}

标签: jsonreactjsreact-nativeexpo

解决方案


尝试 JsonConvert.DeserializeObject 而不是 Parse。你可以在这里查看


推荐阅读