Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/11/2013, 10:56
marielapg84
 
Fecha de Ingreso: agosto-2010
Mensajes: 127
Antigüedad: 14 años, 5 meses
Puntos: 1
Respuesta: Web service con json

encontre l solucion aqui esta

deben tener importadas las siguientes librerias
import org.json.simple.parser.JSONParser;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;


URL url = new URL("http://localhost/stock/rest/provider/STOCK");
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");



BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
while ((output = br.readLine()) != null) {
JSONObject json = (JSONObject) new JSONParser().parse(output);


System.out.println( "valor "+ (String) json.get("STOCK").toString() );

JSONArray genreArray = (JSONArray) json.get("STOCK");

for(int m=0;m<genreArray.size();m++){
JSONObject firstGenre = (JSONObject) genreArray.get(m);
System.out.println("WERKS "+firstGenre.get("CANT1"));


}

}