是否有任何文档说SQLITE Cursor不会显示空值?如您所见,LOGCAT也没有显示空值。
如果是这样,如何为空字段获取空字符串(“”)?我无法用空字段填充我的JSON。例如,在下面的例子中,我想在每个JSON对象中有4个元素,但我只得到2个。
CODE:
String selectQuery = "SELECT * FROM " + TABLE_NAME + " WHERE "+KEY_ID+" = 73";
SQLiteDatabase db = this.getReadableDatabase();
Cursor row = db.rawQuery(selectQuery, null);
if (row.moveToFirst()) {
JSONObject prebook;
do {
Log.d("a1",""+row.getString(3)); //THIS FIELD IS EMPTY
Log.d("a2",""+row.getString(2)); //THIS FIELD IS EMPTY
Log.d("a3",""+row.getString(1)); //THIS FIELD HAS A VALUE
prebook = new JSONObject();
prebook.put(KEY_ID, row.getString(0));
prebook.put(KEY_NAME, row.getString(1));
prebook.put(KEY_PRINT_NAME, row.getString(2)); // THIS ELEMENT NEVER ADDED INTO THE JSON
prebook.put(KEY_GENRE, row.getString(3)); // THIS ELEMENT NEVER ADDED INTO THE JSON
} while (row.moveToNext());
}
logcat的:
12-07 12:43:21.480: D/a3(2283): Farmer Boy