Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
no se puede analizar el valor de la API
{ 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" },

Obtengo los valores anteriores en una de las API de mi proyecto [ http://127.0.0.1:8000/api/invoice_details/8 ], el problema al que me enfrento aquí es que no puedo asignar el parámetro, es decir, agregóInvoiceProductDetails el tipo de lo que estoy obteniendo para el parámetro addedInvoiceProductDetails es como una cadena. Entonces el mapa no funcionará para la cadena. Por lo tanto, ¿cómo puedo convertirlo en objeto y mapearlo?

Nota: la respuesta de la API para el parámetro addedInvoiceProductDetails es la siguiente

[{"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"}]

La respuesta que obtengo de la API se analiza en sí misma, pero aun así, cuando verifico su tipo, se muestra como una cadena.

Sería realmente útil si proporcionara una solución, estoy atascado con este problema de los últimos 2 días.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Necesitas JSON. analizar el valor

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!