Вы находитесь на странице: 1из 3

A)ENVIANDO UN JSON YRECIBIENDO UN JSON

public void agregarPersonal(Grupo dto){


dialogCargando.mostrarDialog();
String url;
Gson gson = new Gson();
String jsonDTO=gson.toJson(dto);
JSONObject jsonObject = null;
try{
jsonObject= new JSONObject(jsonDTO);
}catch(Exception e){
System.out.println("ERROR CREARJSON JSONOBJECT "+e.toString());
}
url="http://"+ipServer+"/KpopWallpaper/public/api/DaoGrupos/agregar";
url=url.replace(" ","%20");
JsonObjectRequest request=new JsonObjectRequest(Request.Method.POST, url,
jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try{
verificarRespuesta= new VerificarRespuesta(response);

}catch(Exception e){
Toast.makeText(context, "ERROR EN EL REGISTRO",
Toast.LENGTH_SHORT).show();
System.out.println("ERROR ORESPONSE AL CREAR PERSONAL
"+e.toString());
dialogCargando.ocultarAlertDialog();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

String elError = "com.android.volley.NoConnectionError:


java.net.ConnectException: Network is unreachable";
String noEncontroServidor = "com.android.volley.TimeoutError";
if (elError.equals("" + error)) {
Toast.makeText(context, "SIN CONEXION A INTERNET",
Toast.LENGTH_LONG).show();
} else {
if (noEncontroServidor.equals("" + error)) {
Toast.makeText(context, "IMPOSIBLE CONECTAR CON
ELSERVIDOR", Toast.LENGTH_SHORT).show();
} else {
System.out.println("ERROR ONERRORRESPONSE AL CREAR ALBUM "+
error.toString());
Toast.makeText(context, "ERROR AL CREAR PERSONAL",
Toast.LENGTH_SHORT).show();
}
}
dialogCargando.ocultarAlertDialog();
}
});
queue.add(request);
}

B)NO ENVIO JSON Y RECIBO UN ARRAY DE JSON


public void obtenerDatos(){
String url;
dialogCargando.mostrarDialog();
url="http://"+ipServer+"/Pemex/public/api/DaoDatos/get/all";
url=url.replace(" ","%20");
JsonArrayRequest request=new JsonArrayRequest(Request.Method.GET, url,
null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try{
Integer tamArray=response.length();
if(tamArray>0){
JSONObject jsonObjectTest= response.getJSONObject(0);
VerificarRespuesta vr=new
VerificarRespuesta(jsonObjectTest);
if(vr.isId("iddatos")){
for (int i=0; i<tamArray; i++){
JSONObject jsonObject= response.getJSONObject(i);

}
myAdapter.setListaDatos(listadoDatos);
}else{
System.out.println("MENSAJE SERVER
"+vr.getMessage("iddatos"));
Toast.makeText(ListadoDatos.this,
vr.getMessage("iddatos"), Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(getApplicationContext(), "NO HAY Datos",
Toast.LENGTH_SHORT).show();
}
dialogCargando.ocultarAlertDialog();
}catch(Exception e){
System.out.println("ERROR JSON ONRESPONSE DATOS
"+e.toString());
dialogCargando.ocultarAlertDialog();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

String elError = "com.android.volley.NoConnectionError:


java.net.ConnectException: Network is unreachable";
String noEncontroServidor = "com.android.volley.TimeoutError";
if (elError.equals("" + error)) {
Toast.makeText(getApplicationContext(), "SIN CONEXION A
INTERNET", Toast.LENGTH_LONG).show();
} else {
if (noEncontroServidor.equals("" + error)) {
Toast.makeText(getApplicationContext(), "IMPOSIBLE CONECTAR
CON ELSERVIDOR", Toast.LENGTH_SHORT).show();
} else {
System.out.println("ERROR ONERRORRESPONSE AL OBTENER LOS
DATOS "+ error.toString());
}
}
dialogCargando.ocultarAlertDialog();
}
});
queue.add(request);
}

Вам также может понравиться