0

I have a table in database with 7 columns and want to send the column #0 and #6 of all rows to my server as json.

type of column 0 is Long and 6 is string.

my code:

Cursor c = datasource.db.rawQuery("select * from posts ",null);
    if (c.moveToFirst()) {
                        ArrayList<Object> list = new ArrayList<Object>();
                        do{
                            Object[] b = new Object[]{c.getLong(0),c.getString(6)};
                            list.add(b);
                        } while  (c.moveToNext());
                        JSONArray jsArray = new JSONArray(list);

                        Log.d("states",jsArray.toString());
                    }

my desired output is this:

[[123,"hash1"],[125,"hash2"]]

but app gives me this output:

["[Ljava.lang.String;@b212d8b8","[Ljava.lang.String;@b212d998"]

1

1 Answer 1

2

i think you need a array list of JSONArray with primitive type

ArrayList<JSONArray> list = new ArrayList<JSONArray>();

and add values this way

JSONArray jArray = new JSONArray(); 
jArray.put(c.getLong(0));
jArray.put(c.getLong(6));
list.add(jArray);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.