Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mx.ipn.escom.clientRest.client;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.util.EntityUtils;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import android.util.Log;
- import com.mx.ipn.escom.clientRest.modelo.Tema;
- public class TemaClient{
- public List<Tema> getTemas(){
- HttpClient httpClient = new DefaultHttpClient();
- HttpGet getData = new HttpGet("http://192.168.1.64:8080/TesterRest/rest/temas");
- getData.setHeader("content-type", "application/json");
- List<Tema> temas = new ArrayList<Tema>();
- try{
- HttpResponse resp= httpClient.execute(getData);
- String respStr = EntityUtils.toString(resp.getEntity());
- JSONArray data = new JSONArray(respStr);//I have the error here
- for(int i=0; i<data.length();i++){
- JSONObject obj = data.getJSONObject(i);
- Integer id = obj.getInt("idTema");
- String nbName = obj.getString("nbTema");
- String dsName = obj.getString("dsTema");
- Tema tema = new Tema(id, nbName, dsName);
- temas.add(tema);
- }
- }catch (Exception e) {
- // TODO: handle exception
- Log.e("Servicio Rest", "Error!", e);
- }
- for(Tema tema : temas)
- System.out.println(tema.getIdTema() + " " + tema.getNbTema() + " " + tema.getDsTema());
- return temas;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement