-2

I am a real newbie so go easy on me and my terminology, I am still learning!

I have a Backendless database I would like to show in my app.

I have successfully connected it to my Android Studio app, queried it and returned the data in the following method:

Backendless.Data.of( "database" ).find( queryBuilder, new AsyncCallback>(){public void handleResponse(List'<'Map'>'response ){

The narrative on the Backendless SDK says "the "response" object is a collection of java.util.Map objects"

I then used an iterator: Iterator itr = response.iterator();

And a while loop to 'get' the object: Object element = itr.next();

I am happy up until this point, the next step is to extract the useful data from element.

I have tried many options of but the only one I have working is element.toString() and use various methods to pick out what I want. This seems so inefficient I thought I would ask the experts for a better option!?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Newbie123
  • 13
  • 2
  • Hi, I noticed a couple of -ve 'reviews' to my question. I am very new to this, can you advise me where I am going wrong with my question? – Newbie123 Nov 02 '17 at 13:59

1 Answers1

0

Your question is rather about working with Java Map interface. So I'd advice you to look into its documentation and maybe some tutorials on this topic.

As to your Backendless question, it looks like you got the request part right. Here is the extended example from the docs, which shows you how to retrieve the object fields:

Backendless.Persistence.of( "Contact" ).find( new AsyncCallback<List<Map<String, Object>>>(){
  @Override
  public void handleResponse( List<Map<String, Object>> foundContacts )
  {
    Iterator<Map<String, Object>> contactsIterator = foundContacts.iterator();
    while( contactsIterator.hasNext() )
    {
      Map<String, Object> contact = contactsIterator.next();
      String name = (String) contact.get( "name" ); // in case you have STRING field 'name' in Backendless database
      Integer age = (Integer) contact.get( "age" ); // in case you have INT field 'age' in Backendless database
      // etc.
    }
  }
  @Override
  public void handleFault( BackendlessFault fault )
  {
    System.out.err( "Failed find: " + fault );
  }
});

As you may see, the main concern is to retrieve a Map instead of Object from the response List.

And also your question would be more useful with code samples of what you tried and maybe direct link to the docs you used as an example.

Scadge
  • 9,380
  • 3
  • 30
  • 39
  • 1
    Scadge, I really appreciate your help and feedback with posing questions, it is much appreciated. I will provide more code and links in the furture. You have solved my issue with the String name = (String) contact.get( "name" ); code. I am sure it seems simple but this has been driving me mad for days! Thanks again. – Newbie123 Nov 02 '17 at 15:03