Retrieving an array from a JSONArray and setting the array to a class variable

brisholx

New Member
After giving up on gson, I've run into what seems to be a very minor issue but I can't seem to identify the problem. I'm simply trying to obtain an array of integers from a JSONArray and save the array of integers to a class variable.\[code\]int length = myArray.length();if(length>0){ for(int j=0; j<length; j++){ JSONArray test = myArray.getJSONArray(j); myArray = new int[test.length()]; for(int k=0; k<test.length(); k++) { myArray[k] = test.getInt(k); }} // However, when I add myArray to the User constructor, the values don't "stick" // ie, User user = new User(x, y, z, myArray); // At this point, myArray doesn't contain its values after I try to access them fromthe // User class\[/code\]Here's the User class:\[code\]public User(String x, String y, int z, int[] myArray){ this.x = x; this.y = y; this.z = z; for(int i=0; i<myArray.length; i++){ Log.v(LOG_TAG, "User: myArray [" + i + "] = " + myArray); this.myArray = myArray; }}\[/code\]When I try to print the contents of User, all of the expected values are there except for the array itself. Thanks.
 
Top