Lomunet Arratiko Lomunet Arratiko - 1 year ago 55
JSON Question

Multidimensional array from JSON -SOLVED-


todosCanales = jo.getJSONArray(JSON_CANALES);


todosCanales = jo.getJSONArray(JSON_CANALES); canales_recv[i] = new String[todosCanales.length()];

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) {
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?

Answer Source

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