通过 curl 连接 GCM 时出现 JSON 异常

Getting JSON Exception While connecting GCM through curl

当我向 GCM 服务器发出 curl 请求时出现错误:

JSON_PARSING_ERROR: Unexpected character (m) at position 0

curl 请求:

curl -i -H "Content-Type: application/json" -H "Authorization: key=AIzaSyAuKLBnVEv_bm4fp88RqKaVm8DClzc" 
-X POST -d "message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]" 
https://android.googleapis.com/gcm/send

我对 GCM 一无所知 API,但我看到了错误。您没有发送有效的 JSON 字符串,服务器无法解析它。

用大括号括起您的数据。替换

-d "message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]"

-d '{"message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]"}'