错误:文字 true 中的字符“”无效(需要“e”)- POST API JSON

问题描述 投票:0回答:1

我正在尝试使用 POST 方法通过 JSON 插入一些来自人的数据。我正在使用 JS 中的代码来构造,但是当我开始转换时,它会向我发送“错误:文字 true 中的无效字符 ' '(需要 'e')”。有谁知道怎么解决吗

const obj = {
  "num_matricula": num_matricula,
  "limit_date": "2022-05-20",
  "admission_date": admission_date,
  "cost_center": cost_center,
  "pos_number": pos_number,
  "role": role,
  "department": department,
  "pagamento": {
    "vinculo": vinculo,
    "valor": valor,
    "recorrencia": recorrencia,
    "contaBancaria": {
      "banco": "001",
      "carta": "c9160763-db6c-4e8c-a1ad-ad8709c99be2"
    }
  },
  "deficiencia": deficiencia,
  "jornada": jornada,
  "profile": {
    "name": name,
    "email": email,
    "mobile": mobile
  },
  "exame": {
    "clinica": "6dc84ce4-7d9f-48ec-b9b1-a8a895a21fd4",
    "data": "2022-05-15",
    "hora": "14:00",
    "obs": "Comparecer de manhã",
    "guia": "e37dab24-c7a4-4b92-b9d1-32ed538b8300",
  },
  "docs": ["c9e26093-5e0c-4bd2-bea3-ac5182a6179f"],
  "send_sms": true,
  "send_email": true
};
const myJSON = JSON.stringify(obj);

有些列已经提供了上一步的数据(您可以在下图中看到),这就是为什么我只是在 JS 代码中重复列名。只是为了让您知道,布尔类型的数据是以下列:send_email、send_sms 和 deficiencia。

javascript json api post pentaho
1个回答
0
投票

问题在于 JSON 是一个字符串。因此,在第一行中,您会看到这不是有效的 json: "num_matricula": num_matricula,

只有数字可以不带双引号:“num_matricula”:1234,

© www.soinside.com 2019 - 2024. All rights reserved.