如何通过SQLite表值排明智成JSON? [英] How to Pass SQLite Table values row wise into JSON?

查看:146
本文介绍了如何通过SQLite表值排明智成JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我通过数据库值到web服务。但它只能通过反感唯一入口valules。我需要一个传递的所有行一成JSON。

Hi I pass the Data base values into webservices. but it passing only resent entry valules only. I need to pass all rows one by one into JSON.

任何一个可以帮助我的样本code。

Can any one help me with sample code.

推荐答案

检查以下code尝试这种方式。这是给你的只是建议。

check below code try this way. this is just advice for you.

            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();

method 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;
            }

这篇关于如何通过SQLite表值排明智成JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆