简体   繁体   中英

ParseObject getString() returns null for Pointer column

I have something like this

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("MyTable");
    query.include("tag");
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> objectList, ParseException e) {
            if (e == null) {
                for(ParseObject objects : objectList) {
                    Log.d(TAG, "parse object name : " + objects.getString("name"));
                    Log.d(TAG, "tag name : " + objects.getString("tag"));
                }
            }
        }
    }

for each row, I have columns like String name and Pointer<Tag> .

在此处输入图片说明

In LogCat, it prints out names correctly, but it prints out null for each tag.

parse object name : Events
tag name : null

I don't actually need to get pointer, but all I need is to get the tag in String format (I can't modify the table to make the column String now).

What can I do to be able to get the Pointer as String format?

Use this to get value from pointer.

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("MyTable");
query.include("tag");
query.findInBackground(new FindCallback<ParseObject>() {
    public void done(List<ParseObject> objectList, ParseException e) {
        if (e == null) {
            for(ParseObject objects : objectList) {
                Log.d(TAG, "parse object name : " + objects.getString("name"));


                ParseObject tagObject=objects.getParseObject("tag");
                //Now access your tag class column
                Log.d(TAG, "tag name : " + tagObject.getString("columnName"));

            }
        }
    }
}

Try on this line code for log

 Log.e(TAG, "tag name : " + objects.getParseObject("tag").getString("col_name");

this way to fetch parse pointer object .

To read value of a pointer,read it as a parse object.

 Log.d(TAG, "tag name : " + objects.getParseObject("tag"));

Note : When you are doing your query you must to include the pointer field if you want to be able to extract the data from it after the query will be returned. The result:

query.include("pointer_filed");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM