0
{
    "msisdnList": [{
        "msisdn": "5409866259"
    }, {
        "msisdn": "5409866260"
    }, {
        "msisdn": "5409866265"
    }, {
        "msisdn": "5409866267"
    }, {
        "msisdn": "5409866299"
    }]
}


public class wrapMsisdnList {
        public String msisdn;
    }

public List<wrapMsisdnList> msisdnList {get;set;}
msisdnList = new List<wrapMsisdnList>();

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://demo9888763.mockable.io/getnumbers/');
request.setMethod('GET');
HttpResponse response = http.send(request);

if (response.getStatusCode() == 200 && response.getBody() != null) {
   
    msisdnList = (List<wrapMsisdnList>)json.deserialize(response.getbody(),List<wrapMsisdnList>.class);
    System.debug('results---->'+ msisdnList);      
           
}

What is the right way of reading the response "System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set "

(List<wrapMsisdnList>)json.deserialize(response.getbody(),List<wrapMsisdnList>.class);
0
0

This isn't a list:

{
    "msisdnList": [{
        "msisdn": "5409866259"
    }, {
        "msisdn": "5409866260"
    }, {
        "msisdn": "5409866265"
    }, {
        "msisdn": "5409866267"
    }, {
        "msisdn": "5409866299"
    }]
}

It's a JSON object with one top-level key, msisdnList, whose value is a list of objects that could be represented by your wrapMsisdnList class.

You'll need an outer wrapper class to represent this:

class OuterWrapper {
    List<wrapMsisdnList> msisdnList;
}

and deserialize to that class instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.