[問題] Push Notification Problem

作者: SONGya168 (威威)   2015-06-02 23:37:18
各位好,
想請問一下,目前我正在進行發送推播的測試
相關註冊及發送訊息都已經OK了,只是目前發生一個問題
想請問各位:
目前參考網路上的範例寫法如下:
Json json = new Json();
json.registration_ids.Add(APP_ID);
json.data = new Message() { message = txtMsg.Text};
JavaScriptSerializer Serializer = new JavaScriptSerializer();
string JsonString = Serializer.Serialize(json);
byte[] JsonBytes = Encoding.UTF8.GetBytes(JsonString);
WebRequest request = WebRequest.Create("https://android.googleapis.com/gcm/se
nd
request.Method = "POST";
request.Headers[HttpRequestHeader.Authorization] = "key=" + API_KEY;
request.ContentType = @"application/json";
request.Credentials = CredentialCache.DefaultCredentials;
request.ContentLength = JsonBytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(JsonBytes, 0, JsonBytes.Length);
stream.Close();
class Json
{
public List<string> registration_ids = new List<string>();
public Message data = new Message();
}
class Message
{
public string message = string.Empty;
}
1.當我輸入的Message中包含空白字元或逗號時,會發生錯誤,查詢之後,似乎
空格對於JSON來說是invalid的,只是這部分是從GCM所回傳的資訊
造成以下錯誤訊息:
org.json.JSONException: Unterminated object at character 20 of
[{message=Terrence Test,....]
這部分我應該如何去進行修正??以讓我能夠送出空格或逗號
小弟在此先謝謝各位
作者: sdyy (中壢市的小智)   2015-06-03 20:39:00
前後加"

Links booklink

Contact Us: admin [ a t ] ucptt.com