0

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 1

1
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);
    }
}
Sign up to request clarification or add additional context in comments.

5 Comments

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

Your Answer

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.