내 안드로이드 응용 프로그램에서 SQlite 내부에 저장된 일부 데이터가 json 파일로 내보내고 게시 HTTP를 통해 서버로 보내고 싶습니다. 실제로이 링크에서 내 코드를 볼 수 있습니다. - Old question containing my code안드로이드 SQlite에서 json
웹을 검색 한 후에는 (json에서 sqlite로) 다른 방법으로 샘플을 찾습니다. 나는 기꺼이 도움을 받거나 올바른 방향으로 나아갈 것입니다.
편집 - GSON을 initilise하는 동안 나는 작은 exeption를 얻을 수
- 문자열 JSON = gson.toJson (기록); . 좀 봐 주 시겠어요 -
public ArrayList<Record> getAllRecordsArray() {
ArrayList<Record> localList = new ArrayList<Record>();
String selectQuery = "SELECT * FROM " + TABLE_RECORD;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
//Loops through all rows and adds them to the local list
if(cursor.moveToFirst())
{
do {
//Get record information
Record record = new Record();
record.setpLat(cursor.getDouble(0));
record.setpLong(cursor.getDouble(1));
record.setpAcc(cursor.getFloat(2));
record.setpTime(cursor.getLong(2));
//Add record to list
localList.add(record);
} while (cursor.moveToNext());
}
return localList;
}
Gson gson = new Gson();
String json = gson.toJson(Record);
이것을 확인하십시오. http://stackoverflow.com/questions/25722585/convert-sqlite-to-json – Rohit5k2
감사합니다. myPath = DB_PATH를 처리 할 때 데이터베이스 경로를 어떻게 알 수 있습니까? – GeoRay
데이터베이스를 작성한 경로. 기본적으로'/ data/data/com.me.myapp/databases/mydb.db'와 같이 사용하거나'String dbname = "mydb.db"; 경로 dbpath = ctx.getDatabasePath (dbname); ' – Rohit5k2