【发布时间】:2019-02-26 01:22:24
【问题描述】:
这是将从 OkHTTP 接收的 JSON 响应。这只是响应的 10 部分中的一部分。
[{"id":418,"title":{"rendered":"testttt"},"content":{"rendered":"
\n\nThis is a random post trying to implement some feature soon and we
don\u2019t have any option rather than try in the production environment only.
Just because this is a stupid decision don\u2019t blame me for this,
please.\n\n<\/p>\n","protected":false}]
这是我试图获得标题的代码 > 呈现如下:
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://url.com/wp-json/wp/v2/posts")
.build();
Response response = client.newCall(request).execute();
String myResponse = response.body().string();
JSONObject json = new JSONObject(myResponse);
for(int i=0; i <=9 ; i++){
JSONArray jsonArray = json.getJSONArray("title");
String title = jsonArray.getString("rendered");
titles.add(title);
}
但我收到了这个error: incompatible types: String cannot be converted to int。
我不知道我错在哪里。
【问题讨论】:
-
你会粘贴完整的 logcat 错误吗?您似乎正在尝试将
String转换为int,这应该在日志中进行检查。 -
在我尝试构建和安装应用程序时出现错误。因此,不会生成任何日志。
-
Android Studio 将此错误指向此行
String title = jsonArray.getString("rendered");