JSON 已读取值但未收到任何内容

JSON value read but nothing received

我正在尝试对“https://gcm-http.googleapis.com/gcm/send”进行 POST。

我收到的连接如下:

200
{"multicast_id":6570365141544424316,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1446150341234481%2c7295a7f9fd7ecd"}]}

换句话说,它正在与 GCM 对话,应该向我的 phone 发送推送通知。但是,我怀疑我发送的 JSON 不正确。这是 JSON:

String json ="{\"registration_ids\" : [\"APA91bGxHWapgmxgyvPceu85ArDMLaFekbTt5RGzy3gv1xtSO09tJbvnaeVLefBqNl_iBrctoZQ2AltSMfrXykq8-AEQtUUWnCVH566xcwib4HinI16W3_g\"],\"notification\" : {\"sound\" : \"default\",\"badge\" : \"1\",\"title\" : \"default\",\"body\"  : \"Test\"},\"data\" : {\"msg\":{\"message\":\"this is it\"}}}";

我不确定如何调试这个问题,因为我没有收到任何东西。如果有人能向我展示正确的语法,我将不胜感激。也许我的语法是正确的,只是没有向 GCM 发送正确的参数?

您可以在以下问题中找到:

final String postData = "{ \"registration_ids\": [ \"" + CLIENT_REG_ID + "\" ], " +
                    "\"delay_while_idle\": true, " +
                    "\"data\": {\"tickerText\":\"My Ticket\", " +
                    "\"contentTitle\":\"My Title\", " +
                    "\"message\": \"Test GCM message from GCMServer-Android\"}}";

当然,您也可以使用 to 和字符串而不是 registration_ids 和数组。

请阅读Google's documentation - Downstream message syntax了解更多详情。希望这对您有所帮助!