[問題] Push Notification Problem

看板AndroidDev作者 (威威)時間10年前 (2015/06/02 23:37), 10年前編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
各位好, 想請問一下,目前我正在進行發送推播的測試 相關註冊及發送訊息都已經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,....] 這部分我應該如何去進行修正??以讓我能夠送出空格或逗號 小弟在此先謝謝各位 -- ◤ ◥█ 咬 ╲ ██ ● ● ██ ╱ 你 ◢███◣ 吼 喔 ◥███◤ ! ! ╱ ██ //// ◥◤ //// ██ ╲ ◥█◣ ╲ │ ╱ ◢█◤ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.3.215 ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1433259448.A.B74.html ※ 編輯: SONGya168 (111.251.3.215), 06/02/2015 23:53:18 ※ 編輯: SONGya168 (111.251.3.215), 06/02/2015 23:54:21 ※ 編輯: SONGya168 (111.251.3.215), 06/02/2015 23:54:45 ※ 編輯: SONGya168 (42.74.255.254), 06/03/2015 09:49:13

06/03 20:39, , 1F
前後加"
06/03 20:39, 1F
文章代碼(AID): #1LRSsujq (AndroidDev)