JSONArray - Só consigo mostrar o último registro
Pessoal, este é o meu arquivo JSON:
Este é o meu arquivo onde recebo o JSON(Android/Java):
O problema, é que tem dois registros no meu arquivo JSON, porém, só está sendo exibido o último registro. Alguém pode me ajudar a resolver o problema?
Obrigado!
[{"id_atleta":"1","nome":"João","clube":"Time do João"},{"id_atleta":"2","nome":"Pedro","clube":"Time do Pedro"}]
Este é o meu arquivo onde recebo o JSON(Android/Java):
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
HttpPost httpPost = new HttpPost(url);
httpResponse = httpClient.execute(httpPost);
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, HTTP.UTF_8);
JSONArray array = new JSONArray(response);
for(int i=0; i < array.length(); i++) {
JSONObject objeto = array.getJSONObject(i);
Funcionario func = new Funcionario();
func.setNome(objeto.get("nome").toString());
func.setClube(objeto.get("clube").toString());
txtNome.setText(func.getNome());
txtClube.setText(func.getClube());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
O problema, é que tem dois registros no meu arquivo JSON, porém, só está sendo exibido o último registro. Alguém pode me ajudar a resolver o problema?
Obrigado!
Jefferson Ferreira
Curtidas 0