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

130
Views
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
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!