获取JSON异常通过curl连接GCM时

时间:2015-02-09 12:42:40

标签: android json curl push-notification google-cloud-messaging

向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

1 个答案:

答案 0 :(得分:2)

我对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"]"}'