3
private static final String URL = "http://www.livroandroid.com.br/livro/carros/carros_{tipo}.json";
public static List<Carro> getCarros(Context context, String tipo) throws IOException {
String url = URL.replace("{tipo}", tipo);
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder()
.url(URL)
.build();
Response response = okHttpClient.newCall(request).execute();
String json = response.body().toString();
List<Carro> carros = parserJSON(context, json);
return carros;
}
如果我調用getCarros
方法時打印出json
變量的值,我看到以下消息在我的logcat:如何從OkHttp響應對象中提取原始JSON字符串?
如何記錄我收到的實際JSON字符串?
也適用於OkHttp 3.0.1 – cwhsu