OnResponse volley with 2 array json! (Web service-android)

0

I am using a web service to bring data from 1 person in particular. and that person has another table with their problems in a database. EJ:

Table 1: id last name 1 Juan Garcia

Table 2 id idUser problem 3 1 I broke something

What I do with the web service is bring 2 array json. The user and the user problems. The php is spectacular and all the code also if nothing else I call the user. But when I try to bring the problems he also compiles me but he throws me "he does not answer" ..

The problem for me is in the onResponse that only 1 object passes through parameters. I was wondering how to do to bring 2 array json in a single call to a webservice. I repeat again. The code goes because when I use 1 single array it works. My question is how to use the 2 arrays.

public class LoginFragment extends Fragment implements Response.Listener<JSONObject>, Response.ErrorListener {

EditText username, password;
Button btn;
ProgressDialog progreso;
RequestQueue request, request2;

JsonObjectRequest jsonObjectRequest;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    View vista = inflater.inflate(R.layout.fragment_login, container, false);
    username = (EditText)vista.findViewById(R.id.input_username);
    password = (EditText)vista.findViewById(R.id.input_password);
    btn = (Button)vista.findViewById(R.id.btn_login);

    request = Volley.newRequestQueue(getContext());

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cargarWebService();
        }
    });

    return vista;
}

private void cargarWebService() {
    progreso = new ProgressDialog(getContext());
    progreso.setMessage("Comprobando datos...");
    progreso.onBackPressed();
    progreso.show();
    String url = "http://192.168.96.1/webservice/login.php?username="+username.getText().toString()+"&password="+password.getText().toString();
    jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, this,this);
    request.add(jsonObjectRequest);
}

@Override
public void onErrorResponse(VolleyError error) {
    progreso.hide();
    Toast.makeText(getContext(), "Datos erroneos. Por favor intente nuevamente "+error.toString(), Toast.LENGTH_SHORT).show();
    Log.i("ERROR", error.toString());
}

@Override
public void onResponse(JSONObject response) {
    progreso.hide();
    Usuario miUsuario = new Usuario();
    problema problema = new problema();
    JSONArray json = response.optJSONArray("usuario");
    JSONArray json2 = response.optJSONArray("problems");
    JSONObject jsonObject = null;
    JSONObject jsonObject1 = null;
    try {

        //Problemas del usuario...
        jsonObject1=json2.getJSONObject(0); //OBTIENE EL INDEX 0. PERO SI SON VARIOS TENDRIA QUE HACER UN FOR. PRIMERO PROBAMOS CON ESTO.
        problema.setSpecialty(jsonObject1.optString("specialty"));
        problema.setDescription(jsonObject1.optString("description"));
       // problema.setFechaIngreso(jsonObject1.optString("created_at"));



        //Datos personales del usuario luego de loguearse. Lo pasamos a la vista userpanel.
        jsonObject=json.getJSONObject(0);
        miUsuario.setId(jsonObject.optString("id"));
        miUsuario.setName(jsonObject.optString("name"));
        miUsuario.setLastName(jsonObject.optString("lastName"));
        miUsuario.setEmail(jsonObject.optString("email"));
        miUsuario.setPhone(jsonObject.optString("phone"));
        miUsuario.setZone(jsonObject.optString("zone"));
       // miUsuario.setDate(jsonObject.optString("date"));


        //Enviando datos por intent hacia la ventanan de userpanel.
        Intent intent = new Intent (getActivity(), userPanel.class);
        intent.putExtra("name", miUsuario.getName());
        intent.putExtra("lastName", miUsuario.getLastName());
        intent.putExtra("email", miUsuario.getEmail());
        intent.putExtra("phone", miUsuario.getPhone());
        intent.putExtra("zone", miUsuario.getZone());
        intent.putExtra("date", miUsuario.getDate());
        intent.putExtra("specialty", problema.getSpecialty());
        intent.putExtra("description", problema.getDescription());
        //intent.putExtra("fecha", problema.getFechaIngreso());
        getActivity().startActivity(intent);
    } catch (JSONException e) {
        e.printStackTrace();
    }

}
    
asked by Juampi 09.10.2018 в 15:53
source

0 answers