dimanche 26 avril 2015

How to store all records into JSON

I am parsing a JSON and trying to store that JSON data into SQLite database, I have only "name" attribute in my JSON and have around 15 records, but i am not able to store all records into SQLite - still only storing last parsed record into JSON

How may i store all records into JSON ?

@Override
        protected Boolean doInBackground(String... urls) {
            try {

                //------------------>>
                HttpGet httppost = new HttpGet(urls[0]);
                HttpClient httpclient = new DefaultHttpClient();
                HttpResponse response = httpclient.execute(httppost);

                // StatusLine stat = response.getStatusLine();
                int status = response.getStatusLine().getStatusCode();

                if (status == 200) {
                    HttpEntity entity = response.getEntity();
                    String data = EntityUtils.toString(entity);


                    JSONObject jsono = new JSONObject(data);
                    JSONArray jarray = jsono.getJSONArray("actors");

                    for (int i = 0; i < jarray.length(); i++) {
                        JSONObject object = jarray.getJSONObject(i);

                        Actors actor = new Actors();

                        actor.setName(object.getString("name"));                        

                        actorsList.add(actor);                      

                        sqliteDB.open();

                        sqliteDB.deleteAll();                                           

                        sqliteDB.insert(object.getString("name"));

                        sqliteDB.close();
                    }
                    return true;
                }

                //------------------>>

            } catch (ParseException e1) {
                e1.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return false;
        }

Aucun commentaire:

Enregistrer un commentaire