我有以下代码:
DBCollection collsc = db.getCollection("StudentCourses") ;
BasicDBObject querysc = new BasicDBObject("StudentID",id );
DBCursor curssc = collsc.find(querysc);
while(curssc.hasNext()) {
DBObject e = curssc.next();
System.out.println("You are currently registered for the following modules: ") ;
System.out.println(e.get("CoursesRegistered")) ;
}
Run Code Online (Sandbox Code Playgroud)
这输出:
You are currently registered for the following modules:
[ "DigitalLogic" "OperatingSystems" , "FundamentalsCSE"]
Run Code Online (Sandbox Code Playgroud)
但是我只希望从数组中返回值,即DigitalLogic,OperatingSystems和FundamentalsCSE.我将使用这些值来填充JList.请帮忙?
Zoo*_*ooz 17
尝试使用
BasicDBList e = (BasicDBList) curssc.next().get("CoursesRegistered");
Run Code Online (Sandbox Code Playgroud)
代替
DBObject e = curssc.next();
Run Code Online (Sandbox Code Playgroud)
然后从e.getIndex(index)获取值;
| 归档时间: |
|
| 查看次数: |
19581 次 |
| 最近记录: |