我正在从 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.
它的工作是因为所有键都有字符串值并且 …