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

185
Views
Enumerar a través de una matriz devuelta por asp.net core web api en javascript

Mi API web principal de asp.net devuelve ID y nombres como este:

 [HttpGet("{id}/names")] public async Task<IEnumerable<VisaNameDto>> GetVisaNames(string id) { visaNames = await visaDtoRepo.GetVisaNames(id); return visaNames; } public class VisaNameDto { public int Id { get; set; } public string Name { get; set; } }

Cuando consumo esta API y la consola inicia sesión en el cliente, obtengo el resultado como:

 const uri = "https://localhost:44395/visa/ae/names"; fetch(uri) .then((response) => response.json()) .then((data) => console.log(data)); ------------------------------------------------------------ {$id: '1', $values: Array(7)} $id: "1" $values: Array(7) 0: {$id: '2', id: 1, name: '48 Hours Transit Visa'} 1: {$id: '3', id: 2, name: '30 Days Tourist Visa'} 2: {$id: '4', id: 3, name: '30 Days Multiple Entry Tourist Visa '} 3: {$id: '5', id: 4, name: '96 Hours Transit Visa'} 4: {$id: '6', id: 5, name: '14 Days Tourist Visa '} 5: {$id: '7', id: 6, name: '14 Days Tourist Visa (Express)'} 6: {$id: '8', id: 7, name: '30 Days Tourist Visa (Express)'} length: 7 [[Prototype]]: Array(0) [[Prototype]]: Object

¿Cómo puedo recorrer esto en JavaScript y acceder a la identificación y el nombre? Ni siquiera obtengo la longitud de esto (data.length muestra undefined). Además, ¿de dónde viene el $id?

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

0

La respuesta es un objeto con propiedades $id y $values .

 const uri = "https://localhost:44395/visa/ae/names"; fetch(uri) .then((response) => response.json()) .then(data => { data.$values.forEach(value => { // do something with value, eg. console.log(value.$id, value.id, value.name) }) });
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!