Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在json中转换fcm通知响应_Php_Android_Json - Fatal编程技术网

Php 在json中转换fcm通知响应

Php 在json中转换fcm通知响应,php,android,json,Php,Android,Json,我从fcm得到上述响应,我想将其转换为json 请检查上面的android代码 正在从remoteMessage获取响应。 我没有在getBody中获取数据。 仅获取空值 Bundle [{ google.sent_time=1487229288769, gcm.notification.created_at=2017-02-16 12:44:52, gcm.notification.e=1, gcm.notification.Content_available=

我从fcm得到上述响应,我想将其转换为json 请检查上面的android代码

正在从remoteMessage获取响应。 我没有在getBody中获取数据。 仅获取空值

Bundle
[{
    google.sent_time=1487229288769,
    gcm.notification.created_at=2017-02-16 12:44:52,
    gcm.notification.e=1,
    gcm.notification.Content_available=1,
    gcm.notification.badge=1,
    gcm.notification.title=, from=388143837768,
    google.message_id=0:1487229288775757%19aca14d19aca14d,
    gcm.notification.body=hi, 
    gcm.notification.uid=160,
    collapse_key=com.sid.Smessenger
}]

从你的回复片段中,我相信你在谈论你应该如何在Android上实现它

它是JSON格式的,但包装在您的数据包中,您作为 FCM receiver函数中的参数尝试从包中获取值,如下所示 通常我们在安卓系统中是这样做的

与其考虑JSON,不如考虑键/值对。你的服务器 以键/值对发送数据。您的应用程序会以以下方式接收该数据: 您获得的意图中的额外项中的键/值对。你知道你的钥匙是什么吗 是,所以只需从绑定到的附加值中检索值 这些键,例如getStringExtramessage、getStringExtratitle


希望这能解决您的问题。

您好,我是andriod的初学者,请您简单解释一下??我不是来为您编写代码的,请阅读JSON文档和有关如何解析它们的意图包。我已经向您展示了如何付出一些努力,不要期望在这里用填鸭式的方式…zzahb=Bundle[{google.sent\u time///some-over-response//collapse\u-key=com.sid.Smessenger}]做一件事将您的代码添加到问题中,您在哪里收到并获得此意图。
public void onMessageReceived(RemoteMessage remoteMessage) 
{
    Log.d(TAG, "FROM: " + remoteMessage.getFrom());
    remoteMessage.getFrom();

    if (remoteMessage.getData().size() > 0) 
        {
        Log.d(TAG, "Message data: " + remoteMessage.getData());
        }
    if (remoteMessage.getNotification() != null) 
       {
        Log.d(TAG, "Message body:" +  
        remoteMessage.getNotification().getBody());

        String questionId =  
        remoteMessage.getData().get("gcm.notification.gid");
        String userId = 
        remoteMessage.getData().get("gcm.notification.uid");
        Log.e("Group ID", questionId);
        Log.e("U ID", userId);

        Bundle bundle = new Bundle();
        for (Map.Entry<String, String> entry :
        remoteMessage.getData().entrySet()) {
            bundle.putString(entry.getKey(), entry.getValue());
            Log.e(entry.getKey(), entry.getValue());

            //run it/// and get notification///
        }
        // String created_at = remoteMessage.
        sendNotification(remoteMessage.getNotification().getBody());
        }

    // String value = bundle.getString("request");
 }