如何访问 RapidApi 城市词典响应正文中的数据 Android

How to access data in response body for RapidApi urban dictionary Android

我收到的响应正文 ** 是 okhttp3.internal.http.RealResponseBody@6e33b4c 如何将其转换为 json 或字符串。

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

           Response response = client.newCall(request).execute();

           Log.d("TAG", "response:toString() " + response.toString());
           Log.d("TAG", "response:headers " + response.headers());
           Log.d("TAG", "response:body " + response.body());
           Log.d("TAG", "response:challenges " + response.challenges());
           Log.d("TAG", "response:message " + response.message());

日志

response:toString() Response{protocol=http/1.1, code=200, message=OK, url=https://mashape-community-urban-dictionary.p.rapidapi.com/define?term=check}

response:headers Cache-Control: no-cache, no-store, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Mon, 13 Apr 2020 11:03:35 GMT
Server: RapidAPI-1.1.0
Via: 1.1 google
X-License: http://api.urbandictionary.com/
X-RapidAPI-Region: AWS - ap-southeast-1
X-RapidAPI-Version: 1.1.0
Content-Length: 4386
Connection: keep-alive

response:body okhttp3.internal.http.RealResponseBody@6e33b4c

response:challenges []

response:message OK

在 RAPID API 开发人员仪表板中,我可以看到响应正文 如何将其转换为字符串或 JSON?

这将得到 JSON

中的列表
  JSONObject object = new JSONObject(response.body().string());

  final JSONArray array = object.getJSONArray("list");