*** Code updated after recommendation **
Hi, I'm trying to parse a multidimensional array from json on my Android Project... I have read a lot of codes from other questions in stackoverflow but i can't understand very well how it works...
this is my JSON file:
and here is my code:
public String[][] parseJSON_canales() {
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(json);
enfrentan = jsonObject.getJSONArray(JSON_ENFRENTAMIENTOS);
canales_recv = new String[enfrentan.length()][];
for (int i = 0; i < enfrentan.length(); i++) {
JSONObject jo = enfrentan.getJSONObject(i);
todosCanales = jo.getJSONArray(JSON_CANALES);
for (int j = 0; j < todosCanales.length(); j++) {
JSONObject jo1 = todosCanales.getJSONObject(j);
canales_recv[i][j] = jo1.getString(CANALES_OBTENIDOS);
}
}
} catch (Exception e) {
e.printStackTrace();
Log.e("MYAPP", "exception: " + e.getCause());
Log.e("MYAPP", "exception: " + e.toString());
}
return canales_recv;
}
I need to get "emite" values inside "equpos" array , any idea from what i'm doing bad?
-
canales_recv[i][j] = jo.getString(CANALES_OBTENIDOS); // change jo to jo1Nisarg– Nisarg2016年06月06日 11:02:34 +00:00Commented Jun 6, 2016 at 11:02
-
Thanks for wanting to mark this as solved, and to offer details about the answer. To do so, please make a self-answer below, so that the original state of the question can be maintained. Thanks.halfer– halfer2016年06月06日 23:39:47 +00:00Commented Jun 6, 2016 at 23:39
1 Answer 1
It Seems alright. BUT you are returning an empty String[][]
return new String[0][0];
you should return your "canales_recv" instead
return canales_recv;
And also as the comment said
canales_recv[i][j] = jo.getString(CANALES_OBTENIDOS); // change jo to jo1
8 Comments
Explore related questions
See similar questions with these tags.