I'm trying to deserialize http json output . Getting an ERROR :System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set
public static void syncBC(){
HttpResponse respond = getrespond();
if(respond.getStatusCode()==200){
list<customerLedgerEntry> clist= new customerLedgerEntry().parse(respond.getbody());
}
}
public static HttpResponse getrespond(){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint ('callout:Bc_test/PBCLE');
request.setHeader('Accept','*/*');
request.setMethod('GET');
request.setTimeout(40000);
HttpResponse response = Http.send(request);
return response;
}
public class customerLedgerEntry{
public String Entry_No;
public Date Posting_Date;
public String Document_Type;
public String Document_No;
public String Customer_No;
public Decimal Amount_LCY;
public Decimal Amount;
public Date Initial_Entry_Due_Date;
public list<customerLedgerEntry> parse(String json){
return(list<customerLedgerEntry>) System.JSON.deserialize(json, list<customerLedgerEntry>.class);
}
}
Here is the JSON output example:
{"@odata.context":"https://api.businesscentral.dynamics.com/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"value":[{"@odata.etag":"W/\"xxxxxxxxxxxxxxxxxxxxxxx\"",
"Entry_No":1,"Posting_Date":"2018-11-05","Entry_Type":"Initial Entry","Document_Type":"xxx",
"Document_No":"xxx","Customer_No":"13",
"Initial_Entry_Global_Dim_1":"",
"Initial_Entry_Global_Dim_2":"",
"Currency_Code":"","Amount":-9,
"Amount_LCY":-9,"Debit_Amount":0,"Debit_Amount_LCY":0,
"Credit_Amount":9,
"Credit_Amount_LCY":9,
"Initial_Entry_Due_Date":"2018-11-05",
"User_ID":"xxxx","xxx":"","Reason_Code":"","Unapplied":false,
"Unapplied_by_Entry_No":0,
"Cust_Ledger_Entry_No":xxx},
{"@odata.etag":"W/\"xxxxxxxxxxxxxxxxxxxxxxx\"",
"Entry_No":2,"Posting_Date":"2018-11-21",
"Entry_Type":"Initial Entry","Document_Type":"xxx",
"Document_No":"1234","Customer_No":"5423","Initial_Entry_Global_Dim_1":"",
"Initial_Entry_Global_Dim_2":"","Currency_Code":"","Amount":-91234.84,"Amount_LCY":-91234.84,"Debit_Amount":0,"Debit_Amount_LCY":0,
"Credit_Amount":91234.84,"Credit_Amount_LCY":91234.84,"Initial_Entry_Due_Date":"2018-11-21","User_ID":"NANCYR","xxx":"","Reason_Code":"",
"Unapplied":false,"Unapplied_by_Entry_No":0,"Cust_Ledger_Entry_No":xxx}]}
Cust_Ledger_Entry_No
isxxx
instead of an actual string like so"xxx"
. You can try validating the JSON here - jsonlint.com.