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

255
Visualizações
How do you extract data from a javascript object when you don’t know the name of the property field because it was is a hashmap object in java?

How do you extract specific data from a javascript object when you don’t know the name of the property field because it is an object that was converted from a hashmap in java?

In my case, I created a Hashmap object in java and using the put method, I put into this object three key/value pairs. This hashmap object is a part of another java model object which just has ordinary fields namely: name (String) and id number(int). I then converted the output of a method that has an object, which includes the two fields and the hashmap object, into a json object to be used in javascript.

The problem is that I can access the name and id fields in javascript by using the dot accessor I.e. obj.name and obj.id but I don’t know how to access the information from the hashmap separately which was converted to json because the key/values don’t have named fields.

When I use the the dot accessor and put in the name of the hashmap object (in other words obj.student where ‘student’ is the name of the hashmap) it gives me both the key and values i.e name of student “Paul” and grade ‘9’ (the hasmap has String for names and int for grades).

What I’d like is to be able to access both key and values separately as I want to use then in a chart js chart.

for (var i=0; i<jsonString.length; i++) {

    let obj = jsonString[i];

    xValues[i] = obj.name;

    yValues[i] = obj.id;

    const myJSON = JSON.stringify(obj.student);
   
 xValuesOne[i] = myJSON;
}

The above code works for extracting the name and id properties but for the student property, as it was a hashmap in java, the specific values don’t have names that I can use to extract the properties.

The string part should be the students name (x-axis) and the int part of the hashmap should be their grade (y-axis).

At the moment in relation to the student data, xValuesOne[i] produces both the string (name) and int (grade) in the x-axis. I would like to extract both the string and the int separately and place them in different axis for chart js.

Any ideas on how to do this?

about 4 years ago · Juan Pablo Isaza
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