繁体   English   中英

无法将包含嵌套对象的JSON数组转换为POJO arraylist

[英]Unable to convert JSON array containing nested objects to POJO arraylist

大家好,我正在用android开发应用程序,我必须能够接收JSON数组并将其转换为普通的旧POJO arraylist。我正在使用GSON来做到这一点,即

Gson gson = new Gson();
ArrayList<AccountTypesRegistered> list = gson.fromJson(responseBody.string(),
                            new TypeToken<ArrayList<AccountTypesRegistered>>() {
                            }.getType());

但是,如果我尝试这样做:

try {
                        for (int i = 0; i < list.size(); i++) {

                            AccountTypesRegistered checklist = list.get(i);

                            Log.e("JsonObject", checklist.toString());

                            Log.e("Name", checklist.getClientNames());
}
                    } catch (Exception e) {

                        e.printStackTrace();
                    }

我在logcat中收到此错误消息:

12-16 03:31:44.371: E/JsonObject(5121): com.nickSoft.dbhelper.AccountTypesRegistered@41d73610
12-16 03:31:44.371: W/System.err(5121): java.lang.NullPointerException: println needs a message
12-16 03:31:44.371: W/System.err(5121):     at android.util.Log.println_native(Native Method)
12-16 03:31:44.371: W/System.err(5121):     at android.util.Log.e(Log.java:232)
12-16 03:31:44.371: W/System.err(5121):     at com.nickSoft.Connections.OkHttpHandlerIncoming$1.onResponse(OkHttpHandlerIncoming.java:91)
12-16 03:31:44.371: W/System.err(5121):     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126)
12-16 03:31:44.371: W/System.err(5121):     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
12-16 03:31:44.371: W/System.err(5121):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-16 03:31:44.371: W/System.err(5121):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-16 03:31:44.371: W/System.err(5121):     at java.lang.Thread.run(Thread.java:841)

这是我的JSON:

[
  {
    "AccountType": "15516321",
    "CustomerName": "1MACMONSAM NICOLAS",
    "Currentbalance": "1100,000.00",
    "AccountKey": "",
    "AllTransactions": [
      {
        "ID": 103,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5001",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:40",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 105,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5002",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 107,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5003",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 109,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5004",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 111,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5005",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 113,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5006",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 115,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5007",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 117,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5008",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 119,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5009",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 121,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "50010",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 103,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "01",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 105,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "02",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 107,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "03",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 109,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "04",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 111,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "05",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 113,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "06",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 115,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "07",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 117,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "08",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 119,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "09",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 121,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "010",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 103,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5001",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 105,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5002",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 107,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5003",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 109,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5004",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 111,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5005",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 113,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5006",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 115,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5007",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 117,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5008",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 119,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5009",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 121,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "50010",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      }
    ]
  },
  {
    "AccountType": "25526322",
    "CustomerName": "2MACMONSAM NICOLAS",
    "Currentbalance": "2100,000.00",
    "AccountKey": "",
    "AllTransactions": [
      {
        "ID": 103,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5001",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:40",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 105,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5002",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 107,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5003",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 109,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5004",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 111,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5005",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 113,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5006",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 115,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5007",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 117,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5008",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 119,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5009",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 121,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "50010",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 103,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "01",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 105,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "02",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 107,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "03",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 109,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "04",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 111,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "05",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 113,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "06",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 115,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "07",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 117,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "08",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 119,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "09",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 121,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "010",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 103,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5001",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 105,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5002",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 107,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5003",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 109,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5004",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 111,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5005",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 113,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5006",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 115,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5007",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 117,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5008",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 119,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5009",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 121,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "50010",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      }
    ]
  },
  {
    "AccountType": "35536323",
    "CustomerName": "3MACMONSAM NICOLAS",
    "Currentbalance": "3100,000.00",
    "AccountKey": "",
    "AllTransactions": [
      {
        "ID": 103,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5001",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:40",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 105,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5002",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 107,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5003",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 109,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5004",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 111,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5005",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 113,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5006",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 115,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5007",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 117,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5008",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 119,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "5009",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 121,
        "DescriptionoOfTransaction": "I need money right now",
        "Debit": "50010",
        "Credit": "0",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      },
      {
        "ID": 103,
        "DescriptionoOfTransaction": "I'am putting in money right now",
        "Debit": "01",
        "Credit": "1500",
        "TransactionDate": "16/12/2016 16:42:41",
        "ValueDate": "16/12/2016 16:42:41"
      }
    ]
  }
]

和类:

public class AccountTypesRegistered {

    private String ClientNames;
    private String AccountTypesOwnedByClient;
    private ArrayList<AccountActivityObject> AccountsActivity;
    private String AccountBalance;
    private String AccountKey;

    public AccountTypesRegistered() {

    }

    ////////////////////////// SETTERS HERE///////////////////////////////////
    public void setAccountTypesOwnedByClient(String AccountTypes) {

        this.AccountTypesOwnedByClient = AccountTypes;
    }

    public void setAccountsActivity(ArrayList<AccountActivityObject> AccountsAct) {
        this.AccountsActivity = AccountsAct;
    }

    public void setClientNames(String Clientna) {
        this.ClientNames = Clientna;
    }

    public void setAccountBalance(String AccountBal) {
        this.AccountBalance = AccountBal;
    }

    public void setAccountKey(String Acctkey) {

        this.AccountKey = Acctkey;
    }

    /////////////////////// GETTERS
    /////////////////////// HERE////////////////////////////////////////////
    public String getClientNames() {
        return this.ClientNames;
    }

    public String getAccountTypesOwnedByClient() {
        return this.AccountTypesOwnedByClient;
    }

    public ArrayList<AccountActivityObject> getAccountsActivity() {
        return this.AccountsActivity;
    }

    public String getAccountBalance() {
        return this.AccountBalance;
    }

    public String getAccountKey() {
        return this.AccountKey;
    }
}

public class AccountActivityObject implements Parcelable {

    private String IdOfTransaction;
    private String DescriptionOftransaction;
    private String ValueDate;
    private String DateofTransaction;
    private String Debit;
    private String Credit;
    private String Closing;
    private String TransactionLinkToAccountKey;

    public AccountActivityObject() {

    }

    /**
     * Use when reconstructing User object from parcel This will be used only by
     * the 'CREATOR'
     * 
     * @param in
     *            a parcel to read this object
     */
    public AccountActivityObject(Parcel in) {

        this.DescriptionOftransaction = in.readString();
        this.IdOfTransaction = in.readString();
        this.ValueDate = in.readString();
        this.DateofTransaction = in.readString();
        this.Debit = in.readString();
        this.Credit = in.readString();
        this.Closing = in.readString();
        this.TransactionLinkToAccountKey = in.readString();

    }

    /**
     * Define the kind of object that you gonna parcel, You can use hashCode()
     * here
     */
    @Override
    public int describeContents() {
        return 0;
    }

    /**
     * Actual object serialization happens here, Write object content to parcel
     * one by one, reading should be done according to this write order
     * 
     * @param dest
     *            parcel
     * @param flags
     *            Additional flags about how the object should be written
     */
    @Override
    public void writeToParcel(Parcel dest, int flags) {

        dest.writeString(DescriptionOftransaction);
        dest.writeString(IdOfTransaction);
        dest.writeString(ValueDate);
        dest.writeString(DateofTransaction);
        dest.writeString(Debit);
        dest.writeString(Credit);
        dest.writeString(Closing);
        dest.writeString(TransactionLinkToAccountKey);

    }

    /**
     * This field is needed for Android to be able to create new objects,
     * individually or as arrays
     *
     * If you don’t do that, Android framework will through exception Parcelable
     * protocol requires a Parcelable.Creator object called CREATOR
     */
    public static final Parcelable.Creator<AccountActivityObject> CREATOR = new Parcelable.Creator<AccountActivityObject>() {

        public AccountActivityObject createFromParcel(Parcel in) {
            return new AccountActivityObject(in);
        }

        public AccountActivityObject[] newArray(int size) {
            return new AccountActivityObject[size];
        }
    };

    // use this to text for equality of objects
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof AccountActivityObject) {
            AccountActivityObject toCompare = (AccountActivityObject) obj;
            return (this.IdOfTransaction.equalsIgnoreCase(toCompare.getIdOfTransaction()));
        }

        return false;
    }

    @Override
    public int hashCode() {
        return (this.getIdOfTransaction()).hashCode();
    }

    ///////////////// SET METHODS/////////////////////////////////////////////
    public void setIdOfTransaction(String IDoftransaction) {
        IdOfTransaction = IDoftransaction;
    }

    public void setDescriptionOftransaction(String Descriptiontransaction) {
        DescriptionOftransaction = Descriptiontransaction;
    }

    public void setValueDate(String ValueDateTransaction) {
        ValueDate = ValueDateTransaction;
    }

    public void setDateofTransaction(String DateTransaction) {
        DateofTransaction = DateTransaction;
    }

    // set Debit if available
    public void setDebit(String DebitAmt) {
        Debit = DebitAmt;
    }

    // set Credit
    public void setCredit(String CreditAmt) {
        Credit = CreditAmt;
    }

    // Always set closing
    public void setClosing(String ClosingAmt) {
        Closing = ClosingAmt;
    }

    public void setTransactionLinkToAccountKey(String TransacLinkToAccountKey) {
        TransactionLinkToAccountKey = TransacLinkToAccountKey;

    }

    ///////////////// GET METHODS/////////////////////////////////////////////

    public String getValueDate() {

        return ValueDate;
    }

    public String getDateofTransaction() {
        return DateofTransaction;
    }

    public String getIdOfTransaction() {
        return IdOfTransaction;
    }

    public String getDescriptionOftransaction() {
        return DescriptionOftransaction;
    }

    // get show Debit if available
    public String getDebit() {
        return Debit;
    }

    // get show Credit if available
    public String getCredit() {
        return Credit;
    }

    // get show Closing
    public String getClosing() {
        return Closing;
    }

    public String getTransactionLinkToAccountKey() {

        return TransactionLinkToAccountKey;
    }
}

请如何解决问题并从JSON获取我的arraylist。 欢迎任何帮助

这是POST还是response 您的JSON看起来不错。 我不熟悉API,但我认为这可能是以下四件事之一:

  1. 如果发布,则可能需要将其转换为javascript对象而不是JSON对象。

    AccountType:“ 15516321”,CustomerName:“ 1MACMONSAM NICOLAS”,Currentbalance:“ 1100,000.00”,AccountKey:“”,...

  2. 根据您发送/接收对象的方式,您可能已经超出了数据量。

  3. 如果您在开发人员控制台中查看,JSON字符串是否出错? 如果字符串对象不好,则开发控制台通常会告诉您。 也许您必须对对象进行编码。

  4. 您的课程定义不正确,因此无法处理数据

编辑

由于这是响应,因此您将能够确定服务器端类对象是否正确处理了数据。 由于您具有嵌套数组,因此我几乎猜到该类对象需要更新其属性。 如果它进入您的浏览器,则可以使用Dev Console看到该对象,我怀疑这是cas,因为您的堆栈跟踪可确定问题所在。

您的模型类是错误的。您应该使用与json键相同的变量名。 与CustomerName一样,您应该在模型类中将CustomerName作为变量。 要么
使用此http://www.jsonschema2pojo.org/ 它将您将json转换为POJO ...

Json不包含ClientNames字段,因此它将在反序列化的对象中填充为null。

在您的日志中,由于正确记录了前一条语句,因此以下行将引发Null指针。 Log.e(“ Name”,checklist.getClientNames());

这意味着Log.e函数获取checklist.getClientNames()为null并在尝试对其进行操作时抛出NPE。

尝试在JSon中添加ClientNames字段,它将正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM