You need to sign in to do that
Don't have an account?
VSK98
Got the error while Parsing JSON System.JSONException: Expected List<ValueWrapper.sub_Cus> but found "[line:1, column:62]
Hi All,
I am getting the error while traversing the JSON. could anybody please suggest me.
JSON Response:
Apex classes :
I am getting the error while traversing the JSON. could anybody please suggest me.
JSON Response:
{ "value": [{ "groupid": null, "group_name": null, "sub_customer": "[{\"CustomerId\":\"94107804\",\"CustomerName\":\"MILTON ULLADULLA HOSPITAL\",\"Street\":\"PRINCES HIGHWAY,\"City\":\"MILTON\",\"PostalCode\":\"2538\",\"Country\": Australia\",\"Assetcnt\":\"0\"},{\"CustomerId\":\"94105686\",\"CustomerName\":\"PORT KEMBLA HOSPITAL\",\"Street\":\"COWPER STREET,\"City\":\"WARRAWONG\",\"PostalCode\":\"2502\",\"Country\": Australia\",\"Assetcnt\":\"0\"},{\"CustomerId\":\"94107702\",\"CustomerName\":\"THE NEW LITHGOW HOSPITAL\",\"Street\":\"Great Western Highway,\"City\":\"LITHGOW\",\"PostalCode\":\"2790\",\"Country\": Australia\",\"Assetcnt\":\"0\"},{\"CustomerId\":\"9487942\",\"CustomerName\":\"SHOALHAVEN DISTRICT MEMORIAL HOSPIT\",\"Street\":\"Shoalhaven Road,\"City\":\"NOWRA\",\"PostalCode\":\"2540\",\"Country\": Australia\",\"Assetcnt\":\"0\"}]" }, { "groupid": 1, "group_name": "PARENT: NEPEAN HOSPITAL", "sub_customer": "[{\"CustomerId\":\"9488490\",\"CustomerName\":\"NEPEAN HOSPITAL\",\"Street\":\"Derby Street,\"City\":\"KINGSWOOD\",\"PostalCode\":\"2750\",\"Country\": Australia\",\"Assetcnt\":\"0\"},{\"CustomerId\":\"9488491\",\"CustomerName\":\"NEPEAN HOSPITAL\",\"Street\":\"Great Western Highway,\"City\":\"PENRITH\",\"PostalCode\":\"2750\",\"Country\": Australia\",\"Assetcnt\":\"0\"},{\"CustomerId\":\"94106344\",\"CustomerName\":\"NEPEAN HOSPITAL\",\"Street\":\"Unit 11, 83 Cox Avenue,\"City\":\"KINGSWOOD\",\"PostalCode\":\"2747\",\"Country\": Australia\",\"Assetcnt\":\"0\"},{\"CustomerId\":\"94126502\",\"CustomerName\":\"NEPEAN HOSPITAL\",\"Street\":\"DERBY STREET,\"City\":\"KINGSWOOD\",\"PostalCode\":\"2747\",\"Country\": Australia\",\"Assetcnt\":\"0\"},{\"CustomerId\":\"94106486\",\"CustomerName\":\"NEPEAN HOSPITAL\",\"Street\":\"SOMERSET STREET,\"City\":\"KINGSWOOD\",\"PostalCode\":\"2747\",\"Country\": Australia\",\"Assetcnt\":\"0\"},{\"CustomerId\":\"9488489\",\"CustomerName\":\"NEPEAN HOSPITAL\",\"Street\":\"Great Western Highway,\"City\":\"PENRITH\",\"PostalCode\":\"2750\",\"Country\": Australia\",\"Assetcnt\":\"0\"}]" }, }] }
Apex classes :
public class ValueWrapper { public class sub_Cus { @AuraEnabled public Double CustomerId {get; set;} @AuraEnabled public Double CustomerName {get; set;} @AuraEnabled public String Street {get; set;} @AuraEnabled public String City {get; set;} @AuraEnabled public String PostalCode {get; set;} @AuraEnabled public String Country {get; set;} @AuraEnabled public String Assetcnt {get; set;} } public class values { @AuraEnabled public Integer groupid {get; set;} @AuraEnabled public string group_name {get; set;} @AuraEnabled public List<sub_Cus> sub_customer {get; set;} } @AuraEnabled public List<values> value {get; set;} }
Public class Vcustomerinfos{ public ValueWrapper wrapper {get;set;} @AuraEnabled public Static void getVcustomerlst(string search){ string toUppercs = search.toUpperCase(); string str; str= toUppercs.trim(); str = str.replaceAll('(\\s+)', '%20'); // White Spacing removing and substitute with %20 system.debug('str*****'+str); / HttpRequest req = new HttpRequest(); string edPnt = '*******'; req.setMethod('GET'); req.setEndpoint(edPnt); req.setTimeout(120000); String username = ********; String password = *********** ; // initialize the variables Blob headerValue = Blob.valueOf(username + ':' + password); req.setHeader('Content-Type', 'application/json'); req.setHeader('Authorization', 'Basic **********'); Http h = new Http(); HttpResponse resp = new HttpResponse(); resp = h.send(req); system.debug('*************'+resp.getbody()); ValueWrapper wrapper; wrapper = (ValueWrapper) JSON.deserializeStrict(resp.getBody(), ValueWrapper.class); -----------------------------------GETTING ERROR system.debug('wrapper********'+wrapper ); } }
Please update your line number 44 with below line:
wrapper = (List<ValueWrapper>) JSON.deserializeStrict(resp.getBody(), Type.forName('List<ValueWrapper>'));
Please like and mark it as best answer if you find it positive.
Thanks,
Jolly Birdi