So I've got a multiple dimensional array with two columns (the number of columns never changes but the number of rows can) and I get how to store a single dimensional array in a JSONArray but I'm having difficulty wrapping my brain around how to store a multidimensional one. It's the syntax of it that I'm trying to figure out. I've tried searching for the solution myself but all I seem to be getting is information dealing with single dimension arrays.
1 Answer
JSONArray multiArray = (JSONArray) JSONSerializer.toJSON(yourArray);
for(int i = 0; i < multiArray .size(); i++){
for(int j = 0; j < multiArray.getJSONArray(i).size(); j++){
test[i][j] = (String) multiArray.getJSONArray(i).get(j);
}
}
5 Comments
EMacKuin
Dammit. It's so bloody obvious when I see it I feel stupid for asking in the first place. >_< Still I GREATLY appreciate the help. Guess I just couldn't see the forest for the trees as usual. Just to check, I assume I just add another layer to the loop if I have 3 columns?
EMacKuin
I think my build path is messed up in some way because now it's saying JSONSerializer can't be resolved. If it's not one thing it's another. Ah well.
EMacKuin
Thank you I realized I didn't have the jar I needed and was trying to find it. I apparently had the wrong one previously.
EMacKuin
I've nearly got this working now that I've added the jar to the build path. It's saying "size" is not a defined method for JSONArray so I used "length" instead and also that "toJSON(String[][])" is undefined for the JSONSerializer though I'm not sure what to put there.