0
在放棄了gson之後,我遇到了似乎很小的問題,但我似乎無法確定問題。我只是試圖從JSONArray中獲取整數數組,並將整數數組保存到類變量中。從JSONArray中檢索數組並將該數組設置爲類變量
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
這裏的用戶等級:
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[i]);
this.myArray[i] = myArray[i];
}
}
當我嘗試打印用戶的內容,所有的預期值都在那裏除了陣列本身。謝謝。
感謝您的建議。我能夠聽從你的建議,但我仍然沒有發現問題。最終,我用ArrayList對象替換了原始數組類型,並且實際上使這些更容易調試。 – user836200 2012-02-11 01:00:36