简体   繁体   中英

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. 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?

Thanks

JSON object requires double quotes around keys and make sure to add content type header

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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