GSON JsonSyntaxException:给出BEGIN_OBJECT而不是STRING

时间:2018-03-17 13:22:12

标签: json string android-studio object gson

我正在创建和应用程序类似于优步但不是创建两个单独的应用程序我将驾驶员和乘客活动放在同一个应用程序中......在驾驶员拒绝乘客请求后,会向驾驶员发送通知,通知他们驱动程序已拒绝请求...此通知生成错误:

  

E / UncaughtException:com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_OBJECT但在第1行第1行为STRING

在乘客应用程序中对该行的称赞

  

LatLng customer_location = new Gson()。fromJson(remoteMessage.getNotification()。getBody(),LatLng.class);

Gson档案

public interface IFCMService {
@Headers({
        "Content-Type:application/json",
        "Authorization:key=xxx"
})
@POST("fcm/send")
Call<FCMResponse> sendMessage(@Body Sender body);

}

MyFirebaseMessagingService

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.d("EARLYBIRD", remoteMessage.getNotification().getBody());

        // Include Latitude and Longitude in firebase message
        LatLng customer_location = new Gson().fromJson(remoteMessage.getNotification().getBody(),LatLng.class);

        Intent intent = new Intent(getBaseContext(), CustomerCall.class);
        intent.putExtra("lat",customer_location.latitude);
        intent.putExtra("lng",customer_location.longitude);
        intent.putExtra("customer",remoteMessage.getNotification().getTitle());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        startActivity(intent);
    }
}

0 个答案:

没有答案