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

159
Views
Typescript JSON.stringify, eliminar el nombre de la propiedad clave

El siguiente JSON Stringify no funciona. Me acabo de dar cuenta de que mi solicitud de API debería verse así sin una clave, para que la API se ejecute correctamente.

 {[{"resource":"Providers"},{"resource":"ServiceLocation"}]}. // this is the json request

en lugar de esto con la tecla bootStrapInputList.

 {"bootStrapInputList":[{"resource":"Providers"},{"resource":"ServiceLocation"}]}

¿Cómo creo un encabezado adecuado, sin una clave?

Tipos de datos:

 export type BootStrapInput = { resource: string; query?: any; }; export type BootStrapResponse = { status: number; resource: string; body: any; };

Servicio:

 export const getBootstrap = ( bootStrapInputList: Array<BootStrapInput>, ): any => { return kfetch(`/api/BootStrap`, { method: 'put', body: JSON.stringify({ bootStrapInputList }), }); }; // this json stringify creates {"bootStrapInputList":[{"resource":"Providers"},{"resource":"ServiceLocation"}]}

Ejecutar servicio:

 (async () => { let bootStrapList: Array<BootStrapInput> = [ { resource: 'Providers' }, { resource: 'ServiceLocation' }, ]; const datatest = await getBootstrap(bootStrapList); // this is not working correctly
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Creo que lo que realmente quieres es hacer lo siguiente en el servicio:

 body: JSON.stringify({ ...bootStrapInputList }),

Esa línea debería dar como resultado:

 {[{"resource":"Providers"},{"resource":"ServiceLocation"}]}

Vi el comentario jsN00b y mientras dijiste que funcionó y, por supuesto, te creo y estoy feliz de que lo hayas resuelto, pero haciendo:

 body: JSON.stringify( bootStrapInputList ),

resultaría en:

 [{"resource":"Providers"},{"resource":"ServiceLocation"}]

Lo cual no es lo mismo (ningún objeto envuelve la matriz).

¡Buena suerte!

about 4 years ago · Santiago Gelvez 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!