PARSING JSON Массив на массив с использованием VOLLEY - PullRequest
0 голосов
/ 04 марта 2020

как разобрать этот json массив

JSON Ссылка

я использую залп, это мой код

private void loadAntrean() {
    requestArray = new JsonArrayRequest(JSON_URL, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {

            JSONObject jsonObject = null;

            for (int i=0; i<response.length(); i++){
                try {
                    jsonObject = response.getJSONObject(i);
                    Antrian antrian = new Antrian();
                    antrian.setPuskesmas(jsonObject.getString("status"));
                    antrian.setId(jsonObject.getString("message"));
                    antrian.setJumlah(jsonObject.getString("data"));
                    lstAntrian.add(antrian);

                    LinearLayoutManager layoutManager = new
                            LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL,
                            false);
                    recyclerView.setHasFixedSize(true);
                    recyclerView.setLayoutManager(layoutManager);
                    adapter = new
                            AntreanAdapter(getApplicationContext(), (ArrayList<Antrian>) lstAntrian);
                    adapter.notifyDataSetChanged();
                    recyclerView.setAdapter(adapter);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d("DEBUGS", "Error: " + error.getMessage());

        }
    });

    requestQueue = Volley.newRequestQueue(MainActivity.this);
    requestQueue.add(requestArray);
}

как я могу разобрать json для самого глубокого массива, потому что я обычно использую только один массив для многих объектов.

1 Ответ

0 голосов
/ 04 марта 2020

Создание json запроса массива

// Tag used to cancel the request
String tag_json_arry = "json_array_req";

String url = "https://api.androidhive.info/volley/person_array.json";

ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();     

JsonArrayRequest req = new JsonArrayRequest(url,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        Log.d(TAG, response.toString());        
                        pDialog.hide();             
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.d(TAG, "Error: " + error.getMessage());
                        pDialog.hide();
                    }
                });

// Adding request to request queue
AppController.getInstance().addToRequestQueue(req, tag_json_arry);

Подробнее здесь: https://www.androidhive.info/2014/05/android-working-with-volley-library-1/

...