comes from the server such json:

{ "command":"client_history_requests", "client_requests": [ {"client_id_request":"10", "client_request_year":"2016", "client_request_mounth":"06", "client_request_day":"07", "client_request_hour":"19", "client_request_minute":"12", "client_request_second":"42"}, {"client_id_request":"11", "client_request_year":"2016", "client_request_mounth":"06", "client_request_day":"07", "client_request_hour":"19", "client_request_minute":"35", "client_request_second":"49"}, {"client_id_request":"12", "client_request_year":"2016", "client_request_mounth":"06", "client_request_day":"07", "client_request_hour":"19", "client_request_minute":"37", "client_request_second":"53"}, {"client_id_request":"13", "client_request_year":"2016", "client_request_mounth":"06", "client_request_day":"07", "client_request_hour":"19", "client_request_minute":"40", "client_request_second":"00"}, ] } 

those. client_requests contains an array. In Android, I do this:

 JSONObject jsonFromServer = new JSONObject(dataFromServer); String command = jsonFromServer.getString("command"); if (command.equals(SERVER_COMMAND_CLIENT_HISTORY_REQUESTS)){ JSONArray arrayClentHistoryRequest = jsonFromServer.getJSONArray("client_requests"); JSONObject jsonArrayRequest= new JSONObject(arrayClentHistoryRequest.getString(1)); Toast.makeText(AddNewRequestActivity.this, jsonArrayRequest.getString("client_request_year"), Toast.LENGTH_LONG).show(); 

and I will be issued in Toast 2016, i.e. the value of the client_request_year of the first element. and how to get client_request_year from the third and so on?

    2 answers 2

     for (int i = 0; i < arrayClentHistoryRequest.length(); i++) { try { JSONObject jsObject = arrayClentHistoryRequest.getJSONObject(i); String clientIdRequest = jsObject.getString("client_id_request"); //И тд } catch (JSONException e) { e.printStackTrace(); } } 

    So try

      You take from the list of arrayClentHistoryRequest only the first string getString (1) and the call Toast goes only to it. I think you should replace 1 with the number of the desired line.