[英]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,但我認為這可能是以下四件事之一:
如果發布,則可能需要將其轉換為javascript對象而不是JSON對象。
AccountType:“ 15516321”,CustomerName:“ 1MACMONSAM NICOLAS”,Currentbalance:“ 1100,000.00”,AccountKey:“”,...
根據您發送/接收對象的方式,您可能已經超出了數據量。
如果您在開發人員控制台中查看,JSON字符串是否出錯? 如果字符串對象不好,則開發控制台通常會告訴您。 也許您必須對對象進行編碼。
您的課程定義不正確,因此無法處理數據
編輯
由於這是響應,因此您將能夠確定服務器端類對象是否正確處理了數據。 由於您具有嵌套數組,因此我幾乎猜到該類對象需要更新其屬性。 如果它進入您的瀏覽器,則可以使用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.