首页 > 数据库技术 > 详细

数据库查询结果用JSON打包为字符串

时间:2015-03-24 19:45:38      阅读:304      评论:0      收藏:0      [点我收藏+]
/**
 * @param mCursor 查询数据库返回的游标
 * @param col查询的总列数
 * @return JSONArray(列名, value)
 * @throws JSONException
 */
private JSONArray handlejson(Cursor mCursor, int col) throws JSONException{
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
if(mCursor == null){
return null;
}
while(mCursor.moveToNext()){
for(int i=0; i<col; i++){
jsonObject = new JSONObject();
for(int j=0; j<col; j++){
jsonObject.put(mCursor.getColumnName(j), mCursor.getString(j));
}
}
jsonArray.put(jsonObject);
}
return jsonArray;
}

本文出自 “爬过山见过海” 博客,请务必保留此出处http://670176656.blog.51cto.com/4500575/1623728

数据库查询结果用JSON打包为字符串

原文:http://670176656.blog.51cto.com/4500575/1623728

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!