Fetching the JSON

In the console, my JSON format looks like
{
“Saad Zahoor”: “jk: (1599694066936)”
}
but when I fetch the json data type into app and store it into string I get different format
String getJSON = response.get(0).getChat().toString();
{rawJsonString={"Saad Zahoor": "hi: (1599694233936)"}, ___class=com.backendless.persistence.JsonDTO}
and when I parse it, it says
No value for Saad Zahoor

What is the proper way to fetch the JSON data type from the backendless??

Other method i try is

 Object getJSON = response.get(0).getChat();
        final ObjectMapper mapper = new ObjectMapper();
        String jsonContent = "";
        try {
              jsonContent = mapper.writeValueAsString(getJSON);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        Toast.makeText(this, "Json Fetched: " + jsonContent, Toast.LENGTH_LONG).show();

but still, I get this format

{"rawJsonString":"{\"Saad Zahoor\": \"hi: (1599694726720)\"}","___class":"com.backendless.persistence.JsonDTO"}

Could you please show how you fetch the data into your app?

static EventHandler<PassengerChauffeurConnection> rtHandler ;
    public void listenToChauffeurLocationUpdates(){
        rtHandler = Backendless.Data.of(PassengerChauffeurConnection.class).rt();
        int token = App.getAppInstance().getIncomingOutgoingRideDetails().getInt(Constants.TOKEN, 0);
        String whereClause = Constants.TOKEN + " = " + token;
        rtHandler.addBulkUpdateListener(whereClause, new AsyncCallback<BulkEvent>() {
            @Override
            public void handleResponse(BulkEvent response) {
                Toast.makeText(RideAccepted.this, "Location detected !! Chauffer is on the move..", Toast.LENGTH_SHORT).show();

                // here get the co-ordinates
                DataQueryBuilder queryBuilder = DataQueryBuilder.create();
                queryBuilder.setWhereClause(whereClause);
                Backendless.Data.of(PassengerChauffeurConnection.class).find(queryBuilder, new AsyncCallback<List<PassengerChauffeurConnection>>() {
                    @Override
                    public void handleResponse(List<PassengerChauffeurConnection> response) {

                        if (response.size() == 1){
                           
                            listenToMessages(response);

                        }


                    }

                    @Override
                    public void handleFault(BackendlessFault fault) {
                        getChauffeurLat = sharedPreferencesIncomingOutgoing.getString(Constants.B_CHAUFFEUR_CURRENT_LAT , "");
                        getChauffeurLong = sharedPreferencesIncomingOutgoing.getString(Constants.B_CHAUFFEUR_CURRENT_LONG , "");

                    }
                });
            }

            @Override
            public void handleFault(BackendlessFault fault) {


            }
        });


    }


 HashMap<String , Object> recordChat = new HashMap<>();
    public void listenToMessages(List<PassengerChauffeurConnection> response){
        Toast.makeText(this, "Inside listen to message", Toast.LENGTH_SHORT).show();
        Object getJSON = response.get(0).getChat();
        Toast.makeText(this, "Object: " + getJSON, Toast.LENGTH_SHORT).show();
        final ObjectMapper mapper = new ObjectMapper();
        String jsonContent = "";
        try {
              jsonContent = mapper.writeValueAsString(getJSON);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        Toast.makeText(this, "Json Fetched: " + jsonContent, Toast.LENGTH_LONG).show();
        Log.i("OKOKOKK" , jsonContent);
}

Thanks. What is the name of the JSON column in the PassengerChauffeurConnection table?

chat

I am getting the response by my json in the console look like

{
"Saad Zahoor": "hi: (1599694726720)"
}

}

and i am getting

{
"rawJsonString":"{\"Saad Zahoor\": \"hi: (1599694726720)\"}",
"___class":"com.backendless.persistence.JsonDTO"
}

What is the data type of the chat field or property in the PassengerChauffeurConnection class?

The data type is JSON for chat column

I am talking about your Java class. You said it has a field/property called chat. My question is what is the data type of that field/property? For example, is it Object, String, HashMap ?

Object

Try changing it to HashMap. The system doesn’t like the JSON field name Saad Zahoor for the reason that it is not a valid java property name (because of a space in the key name). Changing to HashMap might solve the problem.

I still get this kind of format after changing Object to HashMap

I also removed the space from the key i.e
Saad Zahoor to SaadZahoor
but still not getting the proper JSON

What version of Backendless SDK for Android do you use?

‘backendless’, version: ‘5.2.4’

Please make sure to update to the latest version - 6.0.1:
https://search.maven.org/artifact/com.backendless/backendless/6.0.1/jar

[quote=“mark-piller, post:18, topic:11576”]
6.0.1
[/quote]

After upgrading to 6.0.1 from 5.2.4 the response from the backenedless crashes

In version 5.2.4
when i call this below code
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
                    queryBuilder.setWhereClause(whereClause);
                    Backendless.Data.of(PassengerChauffeurConnection.class).find(queryBuilder, new AsyncCallback<List<PassengerChauffeurConnection>>() {
                        @Override
                        public void handleResponse(List<PassengerChauffeurConnection> response) {
                            if (response.size() == 1) {
                            String didChauffeurAcceptTheRide = response.get(0).getRideAcceptedByChauffeur();
                              String didPassengerAcceptTheRide = response.get(0).getRideAcceptedByPassenger();
              
                        }

                        @Override
                        public void handleFault(BackendlessFault fault) {

                        }
                    });

At line where I am getting result from backenedless
String didChauffeurAcceptTheRide = response.get(0).getRideAcceptedByChauffeur();
In 5.2.4 version, it simply gives me the value that is store in the backendless

After converting to the new version
I am getting an error

java.lang.ClassCastException: java.util.HashMap cannot be cast to com.saadBinZahoorOfficial.slipslop.Backendless.PassengerChauffeurConnection

Data type for the column is String

Please post the source code for the PassengerChauffeurConnection class here.
Also, let me know your application ID.