Kendo ui 将mongodb json绑定到剑道网格

Kendo ui 将mongodb json绑定到剑道网格,kendo-ui,kendo-grid,Kendo Ui,Kendo Grid,我对剑道UI非常陌生,遇到了如下类似的挑战(除了我不介意网格有一个固定的数据结构): Json看起来像: [{"score"[{"physics:99", "chemistry" :95}]},{"score"[{"physics:99", "chemistry" :95}]}] 在过去几天里,我一直在努力,并尝试了以下方法: 以下是上述URL中的相关代码: while(cursor.hasNext()) { BasicDBObject obj = (Basic

我对剑道UI非常陌生,遇到了如下类似的挑战(除了我不介意网格有一个固定的数据结构):

Json看起来像:

[{"score"[{"physics:99", "chemistry" :95}]},{"score"[{"physics:99", "chemistry" :95}]}]
在过去几天里,我一直在努力,并尝试了以下方法:

以下是上述URL中的相关代码:

    while(cursor.hasNext()) { 
        BasicDBObject obj = (BasicDBObject) cursor.next();
        jsonobj = new JSONObject();
        BasicDBList name = (BasicDBList) obj.get("Name");
        jsonobj.put("Incident Date", obj.getString("Incident Date"));
        jsonarray.put(jsonobj);
  }
  return jsonarray;
JSON json =new JSON();
String serialize = json.serialize(cursor);

但是剑道格网似乎拒绝了它。请协助。

我的问题通过将返回的json格式化为适当的格式得到解决,如下所示:

发件人:

致:

因此,基本上我提取了score对象,放入我自己的hashmap中,然后返回json对象。请参见下面的示例代码:

*

DB=mongoClient.getDB(“测试”);
DBCollection coll=db.getCollection(“mycol”);
BasicDBObject字段=新的BasicDBObject(“分数”,true)。追加(“\u id”,false);
BasicDBObject查询=新建BasicDBObject();
DBCursor cursor=coll.find(查询,字段)
while(cursor.hasNext()){
DBObject obj=cursor.next();
BasicDBList scoreList=(BasicDBList)obj.get(“分数”);
对于(int i=0;i

*

我能够解决这个问题。问题在于mongoDB发送的json格式。我会尽快回复详细的更新。
    while(cursor.hasNext()) { 
        BasicDBObject obj = (BasicDBObject) cursor.next();
        jsonobj = new JSONObject();
        BasicDBList name = (BasicDBList) obj.get("Name");
        jsonobj.put("Incident Date", obj.getString("Incident Date"));
        jsonarray.put(jsonobj);
  }
  return jsonarray;
JSON json =new JSON();
String serialize = json.serialize(cursor);
[{"score"[{"physics:99", "chemistry" :95}]},{"score"[{"physics:99", "chemistry" :95}]**}]**
[{"physics:99", "chemistry" :95}]},{"score"[{"physics:99", "chemistry" :95}]
DB db = mongoClient.getDB( "test" );
DBCollection coll = db.getCollection("mycol");
BasicDBObject fields = new BasicDBObject("score",true).append("_id",false);
BasicDBObject query = new BasicDBObject();

DBCursor cursor = coll.find(query,fields)

while (cursor.hasNext()) {
    DBObject obj = cursor.next();
    BasicDBList scoreList = (BasicDBList) obj.get("score");

for (int i = 0; i < scoreList.size(); i++) {
        BasicDBObject scoreObj = (BasicDBObject) scoreList.get(i);
        String physics = scoreObj.getString("physics");
        String chemistry = scoreObj.getString("chemistry");
        //ofcourse we need another innerloop here to iterate through
        //all the rows of the returned list.   
        innerMap.add("physics",physics);
        innerMap.add("chemistry",chemistry);
    }       
return new Gson().gson(map.values);
}