Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda