android改造中的动态数据类型处理
我在android应用程序中使用改型,但我的服务有时返回对象数据类型,有时返回数组数据类型。我该怎么办?我在android中使用object来代替数据类型,但无法正确使用它。每当您的服务返回列表时,在接口内创建一个接口,执行以下操作:android改造中的动态数据类型处理,android,json,retrofit2,Android,Json,Retrofit2,我在android应用程序中使用改型,但我的服务有时返回对象数据类型,有时返回数组数据类型。我该怎么办?我在android中使用object来代替数据类型,但无法正确使用它。每当您的服务返回列表时,在接口内创建一个接口,执行以下操作: public Interface EndPointInterface{ @GET(Constants.URL_GET_PHARMACY_REPORT) Call<List<PharmacyReport>> getPharmacy
public Interface EndPointInterface{
@GET(Constants.URL_GET_PHARMACY_REPORT)
Call<List<PharmacyReport>> getPharmacyReport(@Query(Constants.PATIENT_ID) String patientId);
}
public Interface EndPointInterface{
@GET(Constants.URL_FETCH_STORE_INFO)
Call<Store> getStoreInfoByBeaconUUID(@Query(Constants.BEACON_UUID) String beaconUUID);
}
公共接口端点接口{
@获取(常量.URL\u获取\u报告)
调用getPharmacyReport(@Query(Constants.PATIENT_ID)字符串patientId);
}
否则,如果您的服务返回一个对象,请执行以下操作:
public Interface EndPointInterface{
@GET(Constants.URL_GET_PHARMACY_REPORT)
Call<List<PharmacyReport>> getPharmacyReport(@Query(Constants.PATIENT_ID) String patientId);
}
public Interface EndPointInterface{
@GET(Constants.URL_FETCH_STORE_INFO)
Call<Store> getStoreInfoByBeaconUUID(@Query(Constants.BEACON_UUID) String beaconUUID);
}
公共接口端点接口{
@获取(常量.URL\u获取\u存储\u信息)
调用getStoreInfoByBeaconUUID(@Query(Constants.BEACON\UUID)字符串beaconUUID);
}
如果您的后端为同一个api调用返回不同的结果,那么这就是糟糕的api设计:-(在后端尝试创建自己的gson(?)解析器让我检查自己的gson解析器,但在它提供数组和对象的同时,您得到的Json响应是什么请发布response@Nitesh沙玛