How can I extract the raw JSON string from an OkHttp Response object? How can I extract the raw JSON string from an OkHttp Response object? json json

How can I extract the raw JSON string from an OkHttp Response object?


(Originally answered for OkHttp version 2.5.0).

Replace

String json = response.body().toString();

with

String json = response.body().string();

response.body returns a ResponseBody object, which has its own string method: see the source here.


kotlin user try this code 100% tested

val result: String = Gson().toJson(response.body()!!.string())