相关疑难解决方法(0)

如何从OkHttp Response对象中提取原始JSON字符串?

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;
}
Run Code Online (Sandbox Code Playgroud)

如果我json在调用getCarros方法时打印出变量的值,我在logcat中看到以下消息:

com.squareup.okhttp.internal.http.RealResponseBody@1e11866

如何记录我收到的实际JSON字符串?

android json okhttp

3
推荐指数
1
解决办法
9205
查看次数

标签 统计

android ×1

json ×1

okhttp ×1