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

132
Visualizações
Want to get data from a JSONObject

I am working with android studio and I want to retrieve the data from the database mongodb. So I have built the connection and I can get the data in JSON successfully. But when I want to iterate it, it doesn't work.

ArrayList<DatabaseSchema> user = new ArrayList<DatabaseSchema>();

String mongoarray = "{ db_list: " + list + "}";
Object o = com.mongodb.util.JSON.parse(mongoarray);
DBObject dbObj = (DBObject) o;
BasicDBList userList = (BasicDBList) dbObj.get("db_list");

for (Object obj : userList) {
     DBObject userObj = (DBObject) obj;
     DatabaseSchema temp = new DatabaseSchema();
     temp.setUsername(userObj.get("username").toString());
     user.add(temp);
}

And at the end of this method I want to return the user. But when I want to retrieve the username of this user I get nothing and there is no error.

EDIT:

public class DatabaseSchema {
    public String username;

    public void setUsername(String username) {
    this.username = username;
    }

    public String getUsername() {
    return username;
    }
}

and I retrieve this input:

[ { "_id" : { "$oid" : "586.."} , "document" : { "username" : "gmz" } } ]

over 4 years ago · Santiago Trujillo
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