Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 邮递员生成错误:错误:尝试发送POST REGEST时,integer类型的输入语法无效_Javascript_Json_Postgresql_Postman - Fatal编程技术网

Javascript 邮递员生成错误:错误:尝试发送POST REGEST时,integer类型的输入语法无效

Javascript 邮递员生成错误:错误:尝试发送POST REGEST时,integer类型的输入语法无效,javascript,json,postgresql,postman,Javascript,Json,Postgresql,Postman,我对postman JSON post reguest的语法是: { "id": 3, "type": "Colonial", "Location": 1.1, "Postnumber": 1424, "City": "Helsinki", "Reservation_time": "1112" } These column hold values in postgresDB id = serial type = varchar location

我对postman JSON post reguest的语法是:

{
    "id": 3,
    "type": "Colonial",
    "Location": 1.1,
    "Postnumber": 1424,
    "City": "Helsinki",
    "Reservation_time": "1112"
}

These column hold values in postgresDB
id = serial
type = varchar
location = point
postnumber = int
City = varchar
Reservation time = varchar
我不能找出什么是错误的,因为我得到的错误是整数的错误类型

编辑:添加了端点模型和服务

型号:

exports.createTila = async (id, type, location, postnumber, city, reservation_time) => {
  try {
    const result = await client.query(
      "INSERT INTO tila (id, type, location, postnumber, city, reservation_time) VALUES$
      [id, type, location, postnumber, city, reservation_time]
    );
    return result.rows;
  } catch (err) {
    throw new Error(err);
  }
};
服务:

exports.createTila = async (request, response) => {
  try {
    const tilaObject = request.body;
    const newTila = await tilaModel.createTila(tilaObject);
    response.status(200).send(newTila);
  } catch (err) {
    response.status(400).send({ message: err.message });
  }
};

检查您的表字段,任何字段值都将为null,这就是它引发此异常的原因。然后换场地

{
    "id": 3,
    "type": "Colonial",
    "latitude": 1.1,
    "longitude " : 1.1
    "postnumber": 1424,
    "city": "Helsinki",
    "reservation time": "1112"
}

这里的纬度和经度是双精度类型

我认为问题出在
类型的位置,json应该有
纬度
经度
值,而不是像1.1这样的浮点数

{
   "id":3,
   "type":"Colonial",
   "Location":{
      "latitude":35.55689,
      "longitude":51.54865
   },
   "Postnumber":1424,
   "City":"Helsinki",
   "Reservation time":"1112"
}
我发现了我的错误:

而不是像这样在服务中创建对象

exports.createTila = async (request, response) => {
  try {
    const tilaObject = request.body;
    const newTila = await tilaModel.createTila(tilaObject);
    response.status(200).send(newTila);
  } catch (err) {
    response.status(400).send({ message: err.message });
  }
};
我还需要定义服务中db列的值,如下所示:

exports.createTila = async (request, response) => {
  try {
    const {id, type, location, postnumber, city, reservation_time} = request.body;
    const newTila = await tilaModel.createTila(id, type, location, postnumber, city, reservation_time);
    response.status(200).send(newTila);
  } catch (err) {
    response.status(400).send({ message: err.message });
  }
};

我认为问题出在
location
point
类型上,我认为json应该有
纬度
经度
值,而不是像
1.1
那样的浮点数。点类型的正确json语法是什么?我已经添加了它作为答案。将字段“location”更改为:“location”:[11241124124],但我得到了同样的错误。你检查字段值了吗?纬度和经度也会产生同样的错误。