在我的代码中,我使用 for 循环获取了一个数组。该数组包含四个值。如何在文本视图中打印值?我想在四个文本视图中打印这四个值。
我的代码:
HttpClient client2 = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client2.getParams(), 15000);
HttpConnectionParams.setSoTimeout(client2.getParams(), 15000);
HttpUriRequest request2 = new HttpGet(SelectMenuAPI2);
HttpResponse response2 = client2.execute(request2);
InputStream atomInputStream2 = response2.getEntity().getContent();
BufferedReader in2 = new BufferedReader(new InputStreamReader(atomInputStream2));
String line2;
String str2 = "";
while ((line2 = in2.readLine()) != null) {
str2 += line2;
}
JSONObject json3 = new JSONObject(str2);
// message = json2.getString("message");
status = json3.getString("status");
if (status.equals("1")) {
JSONArray school2 = json3.getJSONArray("data");
for (int i = 0; i < school2.length(); i++) {
JSONObject object3 = school2.getJSONObject(i);
Elementarytxt.settext("");
Middle.setText("");
High.setText("");
Atypical.setText("");
}
}
我的 JSON 数据:
{
"status":1,
"data":[
{"title":"Elementary"},
{"title":"Middle"},
{"title":"High"},
{"title":"Atypical"}
]
}