1

I have a class named UserData on parse.com, containing column name as usersports which is of array type,i successfully added strings in the array, but i got stuck while fetching the array values and displaying to a list. say: parse array type is like this,

["Cycling","Diving","Equestrian"]

I have tested using JsonArray for parsing the array values from parse but not succeed. In my code getting checkuserSportarray as null. Please help me out.

Below is my code:

  private void userDetailfromParse(){

         ParseQuery<ParseObject> query = ParseQuery.getQuery(Sportapp.USERDATA);
         query.whereEqualTo(Sportapp.USER_GOOGLE_ID, google_id_from_preference.trim());
         query.getFirstInBackground(new GetCallback<ParseObject>() {
         @SuppressWarnings("unchecked")
        public void done(final ParseObject login_data, ParseException e) {
             if (login_data == null) {
                        Log.d("Data", "The getFirst request failed. in profile"+e.getCode());
                      }
                 else{
                     userEmail = login_data.getString(Sportapp.USER_EMAIL);
                     userName = login_data.getString(Sportapp.USER_NAME);                                       
                     userGender = login_data.getString(Sportapp.USER_GENDER);

                    checkuserSportarray = login_data.getJSONArray(Sportapp.USERDATA);

                    }                         

               }
             });
        }
7
  • Are you sure Sportapp.USERDATA contains ["Cycling","Diving","Equestrian"]? Commented Sep 26, 2014 at 10:55
  • Sportapp.USERDATA is my class name, i have a column named usersports storing ["Cycling","Diving","Equestrian"] which is of array type Commented Sep 26, 2014 at 10:57
  • So you're trying to create an array from your class name? Show us your login_data content Commented Sep 26, 2014 at 11:00
  • i already created array, in the code Snippet, i posted above, in that i am tying to fetch those string values from the array. Commented Sep 26, 2014 at 11:04
  • If checkuserSportarray is null that means that you are not "creating an array" like you're saying. I suggest you debug your login_data content and check it's structure. If you post it here it will be easier to help you Commented Sep 26, 2014 at 11:05

2 Answers 2

2

works fine for me:

    List<String> list11 =  new ArrayList<String>();

    ParseQuery<ParseObject> pQuery = ParseQuery.getQuery("UserData");
    pQuery.whereEqualTo(Sportapp.USER_GOOGLE_ID, google_id_from_preference.trim());
    pQuery.findInBackground(new FindCallback<ParseObject>() {

        @Override
        public void done(List<ParseObject> list, ParseException e) {
            if (e==null) {
            if (list.size()>0) {
                ParseObject p = list.get(0);
                if (p.getList("usersports")!=null) {
                    list11 =  p.getList("usersports");
                }
                else
                {
                    list11= null;
                }
                }}
                        }
                        });

use getList method to get the data from array column of parse table

now if you want to get all individual data of parsed array ,you can simply apply looping on **list11**.

For more info see this link: Parse Object

Sign up to request clarification or add additional context in comments.

1 Comment

i must vote up +1 for this, unfortunately i have less reputation, thanks @userAndroid
1

pass your column name in getJSONArray method like this:-

checkuserSportarray = login_data.getJSONArray("usersports");

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.