0

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

halfer
20.2k20 gold badges111 silver badges208 bronze badges
asked Jun 6, 2016 at 10:50
2
  • canales_recv[i][j] = jo.getString(CANALES_OBTENIDOS); // change jo to jo1 Commented 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. Commented Jun 6, 2016 at 23:39

1 Answer 1

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
answered Jun 6, 2016 at 11:04
Sign up to request clarification or add additional context in comments.

8 Comments

In first place, thank you for your quickly response and help... I have made changes, but I get this error: 06-06 13:24:50.981 13661-13661/in.arenadroid.arenavision W/System.err: java.lang.NullPointerException: Attempt to write to null array
can you please put a log before this line and check if there is any value canales_recv = new String[enfrentan.length()][];
Printing canales_recv.length: 06-06 13:33:47.228 17995-17995/in.arenadroid.arenavision I/System.out: MYAPP: canales_recv: 3 and LOG: pastebin.com/vdda67PS
which one is the line no : 61
canales_recv[i][j] = jo1.getString(CANALES_OBTENIDOS);
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.