lundi 20 juillet 2015

Creating a while loop which insert json data into sqlite (Android)

Basically I am trying to insert the JSON objects the app received into the SQLite database. As I named my JSON object in a continuous ID, I want to create a do while loop to count how many objects it received and stop when the maximum object is received.

My codes is following:

    mydb.StoreMemberInfo(Integer.valueOf(json.getString(TAG_MEMBER_ID).toString()), json.getString(TAG_MEMBER_NAME), Integer.valueOf(json.getString(TAG_MEMBER_POINT).toString()));
                do {
                    mydb.StoreShopInfo(Integer.valueOf(json.getString(TAG_SHOP_ID + ++shop_ID_counter).toString()), json.getString(TAG_SHOP_NAME + ++shop_name_counter));
                }
                while(TAG_SHOP_ID + shop_ID_counter != null);

The JSON objects my app is supposed to receive is as following:

    {"success":1,"message":"Login successful","member_id":"1","member_name":"Peter","member_point":"1000","shop_ID_1":"1","shop_name_1":"Chatime","shop_ID_2":"2","shop_name_2":"Beard Papa","shop_ID_3":"3","shop_name_3":"CoolBlog","friend_ID_1":"2","friend_name_1":"James","friend_ID_2":"3","friend_name_2":"Mary"}

The loop is supposed to stop once it reached shop_ID_4 but because it does not exist but the code is in a waiting state and does not process the other codes instead. What should I do?

Aucun commentaire:

Enregistrer un commentaire