0

嗨,我将数据库值传递给 web 服务。但它仅通过重新发送的条目值。我需要将所有行一一传递到 JSON 中。

任何人都可以帮助我提供示例代码。

4

2 回答 2

1

数据库中的 SQLite

    Cursor cursor;
     cursor = myDataBase.rawQuery(" SELECT " + VENDORID + " FROM  " + VENDORINFO_TABLE
                + " WHERE " + CATEGORYID + "  = " + id,null);
        while (cursor.moveToNext())
       {

         id = cursor.getInt(cursor.getColumnIndex(VENDORID));

          // your JSON put Code 
            JSONObject jsMain = new JSONObject();
        try {
            jsMain.put("email", id);
            return jsMain.toString();
        } catch (JSONException e) {
            e.printStackTrace();
            return "";
        }
}
    cursor.close(); 
于 2012-05-15T11:48:01.810 回答
0

检查下面的代码尝试这种方式。这只是给你的建议。

            Cursor cus = db.selectAll_delete();
            JSONObject jon1 = new JSONObject();
            JSONArray jaa = new JSONArray();
            int i = 0;
            try {
                if (cus.moveToFirst()) {
                    do {
                        String a = cus.getString(1);
                        // Toast.makeText(this, ""+ a,
                        // Toast.LENGTH_LONG).show();
                        JSONObject job_get = getData_b(a);

                        jaa.put(i, job_get);
                        i++;
                    } while (cus.moveToNext());
                }

                jon1.accumulate("details", jaa);
            } catch (Exception e) {
                // TODO: handle exception
            }
              if (cus != null && !cus.isClosed()) {
          cus.close();
                 }

            String js = jon1.toString();
            send_to_server(js);
            Log.d("test json", "" + js);

方法 getData_b();

                 private JSONObject getData_b(String a) {
                // TODO Auto-generated method stub
                Cursor cus = db.fetchRow(a);
                JSONObject job = new JSONObject();
                try {

                    if (cus.moveToFirst()) {
                        do {
                            job.put("B", cus.getInt(1));
                            job.put("I", cus.getString(2));
                            job.put("O", cus.getString(3));
                            job.put("D", cus.getString(4));
                            job.put("D u", cus.getString(5));
                            job.put("L", cus.getString(6));
                            job.put("B", cus.getString(7));
                            job.put("A", cus.getString(8));
                            job.put("K", cus.getString(9));
                            job.put("A", cus.getString(10));
                            job.put("Time", cus.getString(11));
                            job.put("Upd", cus.getString(12));
                            job.put("Deleted", cus.getString(13));

                        } while (cus.moveToNext());
                    }

                } catch (Exception e) {
                    // TODO: handle exception
                }
                return job;
            }
于 2012-05-15T12:15:48.230 回答