PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum JSONArray - Só consigo mostrar o último registro #515462

01/04/2015

0

Pessoal, este é o meu arquivo JSON:


[{"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

Jefferson Ferreira

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar