Answer the question
In order to leave comments, you need to log in
Android (Java) - work with JSON array. How to get all elements one by one?
the following json comes from the server:
{
"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"},
]
}
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();
Answer the question
In order to leave comments, you need to log in
Обернуть последние две строки в for:
for (int i=0; i<arrayClentHistoryRequest .length();i++)
{
Toast.makeText(AddNewRequestActivity.this, arrayClentHistoryRequest .get(i).getString("client_request_year"), Toast.LENGTH_LONG).show();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question