Lomunet Arratiko
Lomunet Arratiko

Reputation: 35

Multidimensional array from JSON

*** 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:

http://pastebin.com/Vf4xWanC

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?

Upvotes: 0

Views: 317

Answers (1)

Abdullah
Abdullah

Reputation: 965

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

Upvotes: 1

Related Questions