相关疑难解决方法(0)

在 Android 中使用 Gson 从通知数据中解析嵌套的 JSON 数组

我正在从 FCM 通知中获取 JSON 格式的数据。它具有基于通知类型的不同格式,如下所示:

格式 1:accept_request:

{
   "alert": "Accept Request By driver",
   "title": "Accept Request By driver",
   "booking_id": "247",
   "notification_type": "accept_request"
}
Run Code Online (Sandbox Code Playgroud)

格式 2:end_request:

{
    "alert": "End trip By driver",
    "title": "End trip By driver",
    "booking_id": "247",
    "notification_type": "end_request",
    "servicesList": [
        {
            "service_id": "1",
            "service_name": "Services1",
            "status": "true",
            "sub_category": [
                {
                    "sub_cat_id": "1",
                    "sub_cat_name": "Doctors on call",
                    "service_cost": "15.00",
                    "service_cat_id": "1",
                    "cost": 0
                }
            ],
            "is_multiple_choose": "0",
            "total_cost": 15
        }
}
Run Code Online (Sandbox Code Playgroud)

我已经创建CommonNotificationBean.java为 POJO 类。我已经成功解析了accept_request.

它的工作是因为所有键都有字符串值并且 …

android json gson firebase-notifications

0
推荐指数
1
解决办法
1823
查看次数

标签 统计

android ×1

firebase-notifications ×1

gson ×1

json ×1