简体   繁体   English

使用嵌套 json object 反应 axios 的发布请求

[英]Post request with nested json object react axios

I am trying to make a post request with nested abject but I got Unexpected token e in JSON at position 0 error.我正在尝试使用嵌套的 abject 发出发布请求,但我Unexpected token e in JSON at position 0 Here is my Code.这是我的代码。

const submit = () => {
    axios
      .post(
        `baseUrl/api/birthCertificate/register`,
        {
          birthCertificate: {
            first_name: "abebe",
            middle_name: "kebede",
            last_name: "kebede",
            date_of_birth: "1998-10-10",
            gender: "male",
            nationality: "22",
            phone_number: "0987654321",
            email: "user27@gmail.com",
            birth_place: {
              country: "chad",
              province: "",
              subProvince: "",
              birthType: "hospital",
              hospitalName: "chad hospital",
            },
            fullNameOfFather: "father full name",
            fullNameOfMother: "mother full name",
            nationalityOfFather: "22",
            nationalityOfMother: "22",
            idCardImage: "idCardImage",
            personImage: "personImage",
            userAddress: {
              region: "Addis Ababa",
              city: "Addis Ababa",
              state: "Addis",
              zone: "02",
              street: "green-street",
              house_number: ".232",
            },
          },
        }
      )
      .then(
        (response) => {
          alert("success");
        },
        (err) => {
          console.log(err);
        }
      );
  };

Is there any other implementation for making this post request with multiple object to make successful post request?是否有任何其他实现可以使用多个 object 发出此帖子请求以成功发出帖子请求?

Thanks谢谢

JSON object requires double quotes around keys and make sure to add content type header JSON object 需要在键周围加上双引号,并确保添加内容类型 header

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM