的陣列通過改造不能得到任何數據,這從服務器參數 https://lao.busnavi.asia/api/location.php?ids%5B%5D=132&ids%5B%5D=133&ids%5B%5D=131
改造解析JSON與參數
JSON的URL請求陣列看起來像這樣 解析JSON時,我有一個問題json data
我的代碼
LatestBusLocation.java
@SerializedName("id") private int id;
@SerializedName("status") private int status;
@SerializedName("route_id") private String routeId;
@SerializedName("lng") private double lng;
@SerializedName("lat") private double lat;
@SerializedName("accuracy") private double accuracy;
@SerializedName("speed") private double speed;
@SerializedName("heading") private float heading;
@SerializedName("date") private Date date;
接口類
public interface ApiService {
@POST("location.php")
Call<LatestBusLocation> loadLatestBusLocation(@Query("ids[]") int[] ids);
}
MainActivity.java
int[] ids = {131, 132, 133};
Call<LatestBusLocation> call = HttpManager.getInstance()
.getService().loadLatestBusLocation(ids);
call.enqueue(new Callback<LatestBusLocation>() {
@Override
public void onResponse(Call<LatestBusLocation> call, Response<LatestBusLocation> response) {
Log.e("WorkOrNote1", "Working");
if (response.isSuccessful()) {
dao = response.body();
Log.d("daoResponse", String.valueOf(dao.getId()));
} else {
try {
Log.e("LatestBusLocation", response.errorBody().string());
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onFailure(Call<LatestBusLocation> call, Throwable t) {
Log.e("onFailure", t.toString());
}
});
你正在使用Gson來解析json嗎? – crgarridos