提供的 URL 為穷游网 最後一刻 列表接口,包含簽名、座標、分頁等參數,返回 JSON 格式數據。
MyResponse resp = new Gson().fromJson(jsonString, MyResponse.class);// 1. 網路請求 (OkHttp/Retrofit)
String json = response.body().string();
// 2. 解析
Gson gson = new Gson();
ApiResponse apiResponse = gson.fromJson(json, ApiResponse.class);
// 3. 更新 UI (主執行緒)
runOnUiThread(() -> {
adapter.setData(apiResponse.getData());
adapter.notifyDataSetChanged();
});
User-Agent、Referer、簽名驗證,直接瀏覽器訪問可能返回 403。@SerializedName("api_field") 映射實際 JSON 鍵名。List<Item> 而非陣列,方便擴展。