lundi 4 avril 2016

How to transfer Downloaded JSONArray to a Database?

Thanks a lot for the previous response to my query I have the JSONArray in buffer.I might be wrong when i say these things,so do correct me.

public void get_data(String data) {

    try {
        JSONArray data_array=new JSONArray(data);

        for (int i = 0 ; i < data_array.length() ; i++)
        {
            JSONObject obj=new JSONObject(data_array.get(i).toString());
            String[] nameArray;
            String[] distArray;
            String[] latArray;
            nameArray[i] = (data_array.getJSONObject(i).getString("rtrname"));
            distArray[i] = (data_array.getJSONObject(i).getString("ctgname"));
            latArray[i] = (data_array.getJSONObject(i).getString("rtrphone"));
            //lonArray[i] = (data_array.getJSONObject(i).getString("longitude"));


        }

        //adapter.notifyDataSetChanged();

    } catch (JSONException e) {
        e.printStackTrace();
    }

Now instead of transferring this data to nameArray[i] and so and so,what should i do to transfer this to a Database(SQLite).Ive already created a DBHlper.java class to deal with it,but im new to this and im missing something.

public boolean insertData(String rtrname, String ctgname,String rtradd1) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues contentValues = new ContentValues();

    //contentValues.put(COL_2,rtrphoneno);
    contentValues.put(COL_2,ctgname);
    contentValues.put(COL_3, rtrname);
    contentValues.put(COL_4, rtradd1);
    long result = db.insert(TABLE_NAME,null ,contentValues);
    if(result == -1)
        return false;
    else
        return true;

1)What should i do in the main class so that i can get each JSONArray node be transferred to the Column of the table??

Aucun commentaire:

Enregistrer un commentaire