从Google Cloud Messaging获取json-commig的数据


Get data of json comming from Google Cloud Messaging

我正试图从谷歌云消息(GCM)中获取一些信息。消息如下:

{
    "category":"com.myappplication",
    "data": {
        "my_message":"this data i need",
        "my_action":"com.google.android.gcm.demo.app.ECHO_NOW"
        },
    "time_to_live"86400,
    "message_id":"5",
    "from":"ADJEKRJEKRJEKJREKRJLSDLKSJDLKJ23DSD22232320DSLKJ23"
}

我只能从"from"、"message_id"answers"time_to_live"中获取数据。

在我的Php脚本中,我解码插入的json消息

    $gcm_in = json_decode(str_replace(""", "'"", $stanza_in->childrens[0]->text));
    $from = $gcm_in->from;

如何获取my_message的信息?

考虑到您指定的json数据存储在变量$data中。

$objData = json_decode($data);
echo $objData->data->my_message;

json_decode函数将json格式的数据转换为php对象。

尽管我不知道为什么要在代码中替换",也不知道最初在哪个变量中接收数据。