i am using FCM
for push messages and handling all incoming push notification in onMessageReceived. Now the issue is with parsing nested json that comes inside this function remoteMessage.getData()
I have following block coming as a push notification in device. content of data payload could be varied here it is dealer later on it can be productInfo
{
"to": "/topics/DATA",
"priority": "high",
"data": {
"type": 6,
"dealerInfo": {
"dealerId": "358",
"operationCode": 2
}
}
}
this how i am parsing it
if(remoteMessage.getData()!=null){
JSONObject object = null;
try {
object = new JSONObject(remoteMessage.getData());
} catch (JSONException e) {
e.printStackTrace();
}
}
now i am getting data with blackslashes as remoteMessage.getData()
returns Map<String,String>
so probably my nested block is being converted in string not sure though.
{
"wasTapped": false,
"dealerInfo": "{\"dealerId\":\"358\",\"operationCode\":2}",
"type": "6"
}
and if i write object = new JSONObject(remoteMessage.getData().toString());
then it got failed with following notification
{
"to": "regid",
"priority": "high",
"notification" : {
"body": "Message Body",
"title" : "Call Status",
"click_action":"FCM_PLUGIN_ACTIVITY"
},
"data": {
"type": 1,
"callNumber":"ICI17012702",
"callTempId":"0",
"body": "Message Body",
"title" : "Call Status"
}
}
error i get is
> org.json.JSONException: Unterminated object at character 15 of
> {body=Message Body, type=1, title=Call Status, callNumber=ICI17012702,
> callTempId=0}