This question already has an answer here:
- JSON Array iteration in Android/Java 6 answers
i have json
array created by php and i want to parse it in java/Android . my array dont have any keys and my this code could not work corretly
PHP Result:
Array
(
[0] => Array
(
[id_] => 30340428
[number] => 10001
[mobile] => 0712200096
[name] => 0
[sms_body] => Hello World
[date] => 2014-10-06 17:09:52
)
[1] => Array
(
[id_] => 30340428
[number] => 10001
[mobile] => 0712200096
[name] => 0
[sms_body] => Hello World
[date] => 2014-10-06 17:09:52
)
)
Json OutPut:
[{"id_":"30340428","number":"10001","mobile":"0712200096","name":"0","sms_body":"Hello World","date":"2014-10-06 17:09:52"},{"id_":"30340428","number":"10001","mobile":"0712200096","name":"0","sms_body":"Hello World","date":"2014-10-06 17:09:52"}]
My Code:
try {
String received = new JsonService(config_username,config_password,0,20,G.F_RECEIVE_SMS).request();
JSONObject object = new JSONObject(received);
for (int i = 0; i < object.length(); i++) {
//String test2 = object.getJSONObject(i).getInt("sms_number") + "";
}
} catch (Exception e) {
e.printStackTrace();
}