获取错误:-S SyntaxError:意外的令牌 < JSON 中的位置 0 REACT

问题描述

 let url = "/"
    fetch(url,{
      headers: {
        "Accept": "application/json","Content-Type": "application/json"
      }
    })
    .then(resp => resp.json())
    .then(data => {
    setToken(1);
   })
   .catch(function(err) {  
    console.log('Fetch Error :-S',err);  
    });

我有一个代理可以:http://localhost:3001/people"

我配置了这个 json-server

{
  "people": [
    {
      "id": "1","name": "gustavo","pass": "gustavo","days": {
        "23/02/2021": [
          {
            "arrive": "09:00","lunchstart": "12:00","lunchend": "13:00","exit": "17:00"
          }
        ],"24/02/2021": [
          {
            "arrive": "09:00","lunchstart": "11:30","exit": "17:00"
          }
        ]
      }
    }
  ]
}

如果使用“/1”就可以了,如何只使用“/”?

我也可以使用 INSOMNIA 或 POSTMAN,它适用于 /people

解决方法

我刚刚将代理更改为:

navigationController?.additionalSafeAreaInsets.top = 30 
  // where 30 is the extra space,add as per your need. 

和获取到:

 "proxy": "http://localhost:3001"

我花了 2 天时间解决了这个问题,但感谢上帝哈哈。

有人有其他解决方案吗?

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...