[Solved] Expected BEGIN_ARRAY but was STRING

I am facing this error in parsing json data :

 Expected BEGIN_ARRAY but was STRING at line 1 column 1156

I could’nt find the solution. My json data is :

    "project": [
            "abbreviation": "abd",
            "customer": "customer1",
            "description": "description1",
            "icon": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAC4UlEQVR42sXTXUhTYRgH8NNNXkTdmPlRpltqalgXZlB4hCC6C8VyYjErtbCoNLJiqQmOtqmYCkUXdhNEGSHYuVXCj81N58dcO+rOPt3c2dnOWTubeSPUv6PZx1U3XfTAj4f3gf/zXL0E8d+LoqgEw+RkvnnOWmi22H6Ytx4bHRtLSt2XSKhUqr8vkMKFYS5I8y5LhGemBYEx8xHPp3CICxpoevFcf3//LrVanaDRaBK0Wu0WnU632XdK8x3E1MxcSZR1Cez7ewgM1IEdqEWYasW6yCMajQqBQGDE5/N98Hq9lNvtppxOJ8UwDEXT9LuJiYmThMlkIuMxUVgXQ1KIw5doEGufOcRjMYiiiEgkAp7nwXEcWJaF3+/HysoKnC7XxtTUdA1hNBrJzUvx+Bpi8Thisbh0+XcwFAohyIUQYANS0A2P2wGXyw6GWdyYMo7VEXq9nuR5QSpeCnDgw0GEQ6x0MQA24MeqzwPvwhiWXzeD7q6CrecibL2XYO2s+DrzoGCEGNcbilmfk3e8fYSlXiWWn13F8vMaLD27gsU+JWydFbDcLcRsVTJmFEmYqdym2AuzcreDGNWbij02A79w/wTmlOmYqz74y6zypwzMVmdi9vIfqjNgrk0cJz5OmIoZI8Vb7kkLruVK8rblbpm/dhjz1yX1ObBsuvHD5tt8K3WQGB43FtPDr3hLYxEW6o/CWl8A280jWLydh+XGHDBNWXA+lMOpksHVnAlnSyYcrTLYW+SwtqS9kBZMkrahPoG+Uwh7w1G4m/LgV2Uh2CZDWJ0BQZOOSMd+RDpTIXSlgJdwnWlY7TjwjdGmtRFvBoeK9C9b7fMNx2J0U67oeHRI9D6WiavtcjH4JEvktBKdXJIusrpU0a9NFj2aFNHefiBsUGVcJk6fObunqbq0SF2aX6IpyyY7yrPIrvPZZHdFDtmjyCV7K/O3+lOFNFPIya4KGdlxQUa2l8lPlR9PS/nnz/gdnPcTQcpv7vgAAAAASUVORK5CYII=",
            "name": "projectname1",
            "plannedEndDate": "2012-05-25T00:00:00+01:00",
            "plannedStartDate": "2012-05-23T00:00:00+01:00",
            "projectStatus": {
                "name": "Opened"
            "realEndDate": "2012-05-25T00:00:00+01:00",
            "realStartDate": "2012-05-23T00:00:00+01:00"

I convert the image to byte array like this :

public static byte[] convertToByteArray(String path) {  
        byte[] imageInByte = null;

            BufferedImage originalImage = 

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write( originalImage, "png", baos );
            imageInByte = baos.toByteArray();


            }catch(IOException e){
        return imageInByte;

And I’m converting the icon from byte array to Bitmap like this :

Bitmap bm = BitmapFactory.decodeByteArray(project.getIcon(), 0,
DisplayMetrics dm = new DisplayMetrics();


The code where I deserialize the JSON response :

Gson gson = new GsonBuilder().setDateFormat(

        final ProjectContainer container = gson.fromJson(resultat,
        final ListView lv = (ListView) findViewById(;

         * Updating parsed JSON data into ListView
         * */
        adaptateur = new ProjectAdapter(ProjectActivity.this,
                R.layout.ligne_project, container);

This is my ProjectContainer class :

  public class ProjectContainer {
        List<Project> projects ;

        public List<Project> getProjects() {
            return projects;

        public void setProjects(List<Project> projects) {
            this.projects = projects;

and this is Project class :

public class Project implements Serializable {

    private static final long serialVersionUID = 1L;
    private ProjectStatus projectStatus;
    private String name;
    private String description;
    private String abbreviation;
    private String customer;
    private Date plannedStartDate;
    private Date plannedEndDate;
    private Date realStartDate;
    private Date realEndDate;
    private Boolean isDeleted;
    private byte[] icon;

    public Project() {

    public Project(String name, String description, String abbreviation,
            String customer, Date plannedStartDate, Date plannedEndDate,
            ProjectStatus projectStatus, Date realStartDate, Date realEndDate) { = name;
        this.description = description;
        this.abbreviation = abbreviation;
        this.plannedStartDate = plannedStartDate;
        this.plannedEndDate = plannedEndDate;
        this.projectStatus = projectStatus;
        this.realStartDate = realStartDate;
        this.realEndDate = realEndDate;
        this.customer = customer;


    public String toString() {
        return name;

    public ProjectStatus getProjectStatus() {
        return this.projectStatus;

    public void setProjectStatus(ProjectStatus projectStatus) {
        this.projectStatus = projectStatus;

    public String getName() {

    public void setName(String name) { = name;

    public String getDescription() {
        return this.description;

    public void setDescription(String description) {
        this.description = description;

    public String getAbbreviation() {
        return this.abbreviation;

    public void setAbbreviation(String abbreviation) {
        this.abbreviation = abbreviation;

    public Date getPlannedStartDate() {
        return this.plannedStartDate;

    public void setPlannedStartDate(Date plannedStartDate) {
        this.plannedStartDate = plannedStartDate;

    public Date getPlannedEndDate() {
        return this.plannedEndDate;

    public void setPlannedEndDate(Date plannedEndDate) {
        this.plannedEndDate = plannedEndDate;

    public Date getRealStartDate() {
        return this.realStartDate;

    public void setRealStartDate(Date realStartDate) {
        this.realStartDate = realStartDate;

    public Date getRealEndDate() {
        return this.realEndDate;

    public void setRealEndDate(Date realEndDate) {
        this.realEndDate = realEndDate;

    public byte[] getIcon() {
        return this.icon;

    public void setIcon(byte[] icon) {
        this.icon = icon;

    public String getCustomer() {
        return this.customer;
    public void setCustomer(String customer) {
        this.customer= customer;

I would greatly appreciate if you can help me solve this problem. Thanks in advance

Enquirer: Wijden


Solution #1:

The Exception is thrown when you try to parse the field "icon", because in your JSON response there is a string, and you try to parse it as a byte[].

Since in your class, icon is an array of bytes, when it tries to parse the field "icon" it says it “expected an array“, but in the JSON response "icon" is not an array (there’s nothing surrounded by [ ]), so it says “but was a string“…

EDIT: That said, in order to fix it, the easiest way in my opinion is to change the type of icon for a String to parse it correctly, and then do the conversion to byte[] somewhere else… For example you can have a method in the class, let’s say public byte[] getIconAsByteArray() {...}, that does the conversion.

Otherwise, and this is probably the most elegant solution, you need to write a custom deserializer.

Respondent: MikO

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy