简体   繁体   English

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

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

Good day all, i'am developing app in android and i have to be able to recieve JSON array and convert it to plain old POJO arraylist.I'm using GSON to do this ie 大家好,我正在用android开发应用程序,我必须能够接收JSON数组并将其转换为普通的旧POJO arraylist。我正在使用GSON来做到这一点,即

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

however if i try to do: 但是,如果我尝试这样做:

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();
                    }

i get this error message in logcat: 我在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)

Here is my JSON: 这是我的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"
      }
    ]
  }
]

and the classes: 和类:

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;
    }
}

Please how to solve the problem and get my arraylist from the JSON. 请如何解决问题并从JSON获取我的arraylist。 Any help is welcome 欢迎任何帮助

Is this POST or response ? 这是POST还是response Your JSON looks fine. 您的JSON看起来不错。 Not familiar with the API but I think it may be one of four things: 我不熟悉API,但我认为这可能是以下四件事之一:

  1. If posting you may want to convert this into a javascript object not a JSON object. 如果发布,则可能需要将其转换为javascript对象而不是JSON对象。

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

  2. You may have exceeded the amount of data based on how you are sending/receiving the object. 根据您发送/接收对象的方式,您可能已经超出了数据量。

  3. If you look in your dev console is the JSON string erroring out? 如果您在开发人员控制台中查看,JSON字符串是否出错? If the string object is bad the dev console typically tells you. 如果字符串对象不好,则开发控制台通常会告诉您。 Maybe you have to encode the object. 也许您必须对对象进行编码。

  4. Your class is not properly defined so it cannot handle the data 您的课程定义不正确,因此无法处理数据

EDIT 编辑

Since this is a response you will be able to determine whether or not your server-side class object is handling the data correctly. 由于这是响应,因此您将能够确定服务器端类对象是否正确处理了数据。 Since you have nested array I am almost guessing the class object needs its properties updated. 由于您具有嵌套数组,因此我几乎猜到该类对象需要更新其属性。 If it makes it to your browser you can see the object using Dev Console which I doubt that is the cas since your stack trace identifies the issue. 如果它进入您的浏览器,则可以使用Dev Console看到该对象,我怀疑这是cas,因为您的堆栈跟踪可确定问题所在。

Your model class is wrong.. You should have same variable names as the key of json. 您的模型类是错误的。您应该使用与json键相同的变量名。 Like for CustomerName you should have CustomerName as variable in your model class. 与CustomerName一样,您应该在模型类中将CustomerName作为变量。 Or 要么
Use this http://www.jsonschema2pojo.org/ . 使用此http://www.jsonschema2pojo.org/ It converts you json to POJO... 它将您将json转换为POJO ...

The Json does not contain ClientNames field and hence it would be populated as null in the deserialized Object. Json不包含ClientNames字段,因此它将在反序列化的对象中填充为null。

From your log the following line throws Null Pointer as its previous statement is logged properly. 在您的日志中,由于正确记录了前一条语句,因此以下行将引发Null指针。 Log.e("Name", checklist.getClientNames()); Log.e(“ Name”,checklist.getClientNames());

This means that Log.e function gets checklist.getClientNames() as null and throws NPE while trying to work on it. 这意味着Log.e函数获取checklist.getClientNames()为null并在尝试对其进行操作时抛出NPE。

Try adding the ClientNames field in JSon and it would work fine. 尝试在JSon中添加ClientNames字段,它将正常工作。

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

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