Converting OkHttp response body to readable format when using RapidAPI dictionary service

I’m working with RapidAPI to fetch dictionary definitions in my Android app, but I’m having trouble reading the actual response data. When I try to access the response body, I only get something like okhttp3.internal.http.RealResponseBody@7a8b2d1 instead of the actual JSON content.

OkHttpClient httpClient = new OkHttpClient();
Request apiRequest = new Request.Builder()
        .url("https://mashape-community-urban-dictionary.p.rapidapi.com/define?term=awesome")
        .get()
        .addHeader("x-rapidapi-host", "mashape-community-urban-dictionary.p.rapidapi.com")
        .addHeader("x-rapidapi-key", MY_API_KEY)
        .build();

Response apiResponse = httpClient.newCall(apiRequest).execute();

Log.d("API_CALL", "Full response: " + apiResponse.toString());
Log.d("API_CALL", "Response headers: " + apiResponse.headers());
Log.d("API_CALL", "Response body: " + apiResponse.body());
Log.d("API_CALL", "Status message: " + apiResponse.message());

The logs show everything looks correct - status 200, proper headers with content-type as application/json, but the body just shows the object reference. In the RapidAPI dashboard I can see the actual JSON response perfectly. How can I extract the real content from this response body object?

yeah this is pretty straightforward - you just need to actually read the response body content. try apiResponse.body().string() instead of just apiResponse.body(). what ur seeing is just the object reference not the actual json data. worked for me when i had same issue with rapidapi endpoints.

You’re running into this because ResponseBody in OkHttp doesn’t automatically convert to a readable string when you log it directly. The object reference you’re seeing is normal Java behavior for toString() on complex objects. What worked for me in similar situations was extracting the content first before logging. Replace your response body logging with something like String responseData = apiResponse.body().string(); Log.d("API_CALL", "Response body: " + responseData); One important thing I learned the hard way - once you call string() on the ResponseBody, it’s consumed and can’t be read again. So if you need the data elsewhere in your code, store that responseData variable and reuse it rather than trying to call string() multiple times on the same response body.

The issue you’re encountering is actually quite common when working with OkHttp. When you call apiResponse.body(), you’re getting a reference to the ResponseBody object itself, not its content. You need to call the string() method on that ResponseBody to actually read the JSON data. Try changing your last log statement to Log.d("API_CALL", "Response body: " + apiResponse.body().string()); and you should see the actual JSON content. Keep in mind that ResponseBody can only be consumed once, so if you need to use the response data multiple times, store it in a String variable first. Also make sure you’re handling this on a background thread since network operations and response body reading should never be done on the main UI thread.