안녕하세요.
GCM 에서 받아온 메세지를 JSONObject 객체로 만드려는데, 계속 아래와같은 오류가 발생합니다.
ERROR ----Value Bundle of type java.lang.String cannot be converted to JSONObject
받아온 GCM 메세지를 찍어보면 아래와 같습니다.
Received: Bundle[{android.support.content.wakelockid=2, collapse_key=1, from=969710237186}]
JSONObject로 만드려면 어떻게 해야 할까요?
서버에서 보낼 때는 아래와 같은 구조로 보냈습니다.
1
2
3
4
5
6
|
JSONObject jsonObject = new JSONObject();
jsonObject.put("collapse_key",String.valueOf(1));
jsonObject.put("time_to_live",108);
jsonObject.put("delay_while_idle",true);
jsonObject.put("registration_ids",new JSONArray(reg_list));
|
Push메세지를 받아와서 처리하는 Intent는 아래와 같습니다..
에러는 13번째 줄에서 발생합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
@Override
protected void onHandleIntent(Intent intent) {
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Log.i(TAG, "Received: " + extras.toString());
pushProcess(extras.toString());
}
}
}
private void pushProcess(String jsonString) {
try {
JSONObject obj = new JSONObject(jsonString);
} catch (JSONException e) {
Log.d(TAG,"ERROR ----" + e.getMessage());
}
}
|
조언 부탁드립니다.
감사합니다!