Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
unable to parse API value
{
id: 8,
customerName: "xyz",
customerMobileNumber: "123456789",
customerBillingAddress: "xyz address",
customerShippingAddress: "xyz address",
customerProductPurchasedDate: "2021-11-09T09:07:00.000Z",
customerGstNumber: "xyz",
customerHsnNumber: "xyz",
addedInvoiceProductDetails: "[{"productquantity":"5","productprice":"5","productgst":"5","productname":"xyz","producttotalprice":"26.25","id":"2021-11-13T09:08:20.071Z"}]",
created_at: "2021-11-13T09:08:25.000000Z",
updated_at: "2021-11-13T09:08:25.000000Z"
},

I'm getting above values in one of my project API[http://127.0.0.1:8000/api/invoice_details/8], The issue here im facing is that im unable to map the parameter i.e., addedInvoiceProductDetails the typeof im getting for the parameter addedInvoiceProductDetails is as string. So map wont work for string. Hence how can i convert it to object and map it.

Note: I'm getting the response from API for addedInvoiceProductDetails parameter is as below

[{"productquantity":"1","productprice":"1000","productgst":"18","productname":"Street Light","producttotalprice":"1180","id":"2021-11-18T12:11:31.137Z"},{"productname":"Solar","productquantity":"2","productprice":"50","productgst":"10","producttotalprice":"110","id":"2021-11-18T12:11:43.935Z"}]

The response what im getting from API is parsed one itself, but still when i check its typeof it is giving as string.

it would be really helpful if i have provide with solution, im stuck with this issue from past 2 days.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to JSON.parse the value

const response = [{
    id: 8,
    customerName: "xyz",
    customerMobileNumber: "123456789",
    customerBillingAddress: "xyz address",
    customerShippingAddress: "xyz address",
    customerProductPurchasedDate: "2021-11-09T09:07:00.000Z",
    customerGstNumber: "xyz",
    customerHsnNumber: "xyz",
    addedInvoiceProductDetails: "[{\"productquantity\":\"5\",\"productprice\":\"5\",\"productgst\":\"5\",\"productname\":\"xyz\",\"producttotalprice\":\"26.25\",\"id\":\"2021-11-13T09:08:20.071Z\"}]",
    created_at: "2021-11-13T09:08:25.000000Z",
    updated_at: "2021-11-13T09:08:25.000000Z"
  },
  {
    id: 10,
    customerName: "xyz",
    customerMobileNumber: "123456789",
    customerBillingAddress: "xyz",
    customerShippingAddress: "xyz",
    customerProductPurchasedDate: "2021-11-11T09:26:00.000Z",
    customerGstNumber: "xyz",
    customerHsnNumber: "xyz",
    addedInvoiceProductDetails: "[{\"productquantity\":\"5\",\"productprice\":\"5\",\"productgst\":\"5\",\"productname\":\"gggg\",\"producttotalprice\":\"26.25\",\"id\":\"2021-11-13T09:27:17.639Z\"}]",
    created_at: "2021-11-13T09:27:20.000000Z",
    updated_at: "2021-11-13T09:27:20.000000Z"
  },
]

response.forEach(({addedInvoiceProductDetails})=> console.log(JSON.parse(addedInvoiceProductDetails)))

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda