Below this is my Json which is valid. I use this JSON to send notifications on Android and iOS devices using SNS. However,
{
"default": "",
"GCM": "{ \"data\": { \"message\": \"{'user_id':'48491','story_title':'Who is Trumps dangerous best friend?','story_slug':'Who-is-Trumps dangerous best friend?','story_id':'40372','user_full_name':'Gourav Choubey','cover_image':'url','user_profile_photo':'url'}\" } }"
}
When I add an ' (Single Qoute) to the title, such as the JSON below, is still a valid JSON but on the Device side, the JSON decode is unable to read the JSON, due to single qoute on also Story_title, and it's key also starts with a single qoute.
But the Android app is unable to show the single qoutation (') and nothing is shown in the notification.
{
"default": "",
"GCM": "{ \"data\": { \"message\": \"{'user_id':'48491','story_title':'Who is Trump's dangerous best friend?','story_slug':'Who-is-Trumps dangerous best friend?','story_id':'40372','user_full_name':'Gourav Choubey','cover_image':'url','user_profile_photo':'url'}\" } }"
}
I tried HTML encoding, and backslash to escape the single qoute.
However nothing works, without giving an update to the app, how do I make sure the single qoute is correctly sent?
The end device only takes in the string I sent.
Here is my PHP code.
$android_notification_fields = array(
"user_id" => $result->user_id,
"story_title" => addslashes($title),
"story_id" => $result->story_id,
"user_full_name" => addslashes($result->user_full_name),
"cover_image" => $result->cover_image,
'user_profile_photo' => $result->user_profile_photo
);
$push_message = '{ "default": "", "GCM":"{\"data\":{\"message\": \"'.str_replace('"', "'", str_replace('\\','',utf8_encode(json_encode($android_notification_fields)))).'\"}}"}';
print_r($push_message);
$topic_arn = $this->android_topic_arn;
}
I know this is simple, (I do the backend in PHP). I am trying to solve this from a number of days, any help will be really appreciated. I wanna avoid changing anything on the Android App.