0

Hello everybody I am kind of new to json and javascript, I am trying to get specific data from my json array..

this is my: Json array

how can I get specific data like InfoParticipante->Nombre->SOLIS DIAZ HECTOR JAVIER

or Participante->Conceptos->Concepto->Importe => "68800.00"

Any help would appriciate it alot!

BetoIGM
  • 157
  • 1
  • 2
  • 16
  • still no :( I am looking for something to start – BetoIGM Mar 13 '20 at 16:41
  • Can you copy paste the response from console.log(responseJSON) into the question itself? – Lucas Raza Mar 13 '20 at 16:46
  • Ready @LucasRaza thanks for your help :D – BetoIGM Mar 13 '20 at 17:08
  • Does this answer your question? [How do I extract data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) – miken32 Mar 13 '20 at 17:17
  • I updated my response. What helped me when I was learning to access properties on a JSON was doing a lot of console.log's to see what each property returns.. For example try console.log(responseJson[0]) then move to console.log(responseJson[0].Particpante[1]) and see what that returns. Also, I'm not completely sure what response.json() does.. Try 'return JSON.parse(response)' – Lucas Raza Mar 13 '20 at 17:20
  • @miken32 that solution is on PHP, what i am looking for is to extract data on javascript...of course that solution helps but its a more a conceptual solution than a direct solution. Anyway I will give it a try, thanks! – BetoIGM Mar 13 '20 at 17:30
  • Sorry, did not read enough of the question! – miken32 Mar 13 '20 at 17:32
  • @LucasRaza Hello , when I try 'return JSON.parse(response)' I get in console log this: Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1 at Object.parse () at bundle.js:831 – BetoIGM Mar 13 '20 at 18:04

1 Answers1

0

Your JSON is enclosed in an array so you first want to start by making sure you are in the 1st index of that array.. If you assign the JSON to a variable you can access that property like so

var JSON;
// InfoParticipante->Nombre
var Nombre = JSON.Participante.InfoParticipante.['@attributes'].Nombre;
Lucas Raza
  • 499
  • 1
  • 4
  • 13
  • 1
    `.@attributes` will not work in JS. You need to use square bracket notation for that property – JAAulde Mar 13 '20 at 17:09
  • Hello my friend @Lucas Raza! When I try console.log(responseJson[0]); I get the next result: undefined but when I try console.log(responseJson); I get the complete JSON data in console log.. very strange :/ – BetoIGM Mar 13 '20 at 18:07
  • `InfoParticipante[0].['@attributes']` is not valid--you'll need to remove the `.` before the square bracket notation: `InfoParticipante[0]['@attributes']` – JAAulde Mar 13 '20 at 18:08
  • Okai now it's working like this: console.log(responseJson.Participante.InfoParticipante['@attributes'].Nombre); THANKS @Lucas Raza :D – BetoIGM Mar 13 '20 at 18:31
  • My bad! The way that the JSON is makes it look like there are many arrays, I'll update my answer – Lucas Raza Mar 13 '20 at 21:12