2

i am getting this error. java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 44.

i know there are similar questions on this issue, they just didn't help me. my json string is in correct format because i can view it in any json editor.

it worked for me before with different json strings, please tell me whats wrong with this one.

this is my code:

Gson gson = new Gson();
data = gson.fromJson(result, Data3Nir.class);

this is the java data object

public class Data3Nir {

private List<LinksEntity> links;

public void setLinks(List<LinksEntity> links) {
    this.links = links;
}

public List<LinksEntity> getLinks() {
    return links;
}

public static class LinksEntity {


    private LinkEntity link;

    public void setLink(LinkEntity link) {
        this.link = link;
    }

    public LinkEntity getLink() {
        return link;
    }

    public static class LinkEntity {
        private String title;
        private String link_place_in_list;
        private String web_link;


        private WebLinkIconEntity web_link_icon;

        public void setTitle(String title) {
            this.title = title;
        }

        public void setLink_place_in_list(String link_place_in_list) {
            this.link_place_in_list = link_place_in_list;
        }

        public void setWeb_link(String web_link) {
            this.web_link = web_link;
        }

        public void setWeb_link_icon(WebLinkIconEntity web_link_icon) {
            this.web_link_icon = web_link_icon;
        }

        public String getTitle() {
            return title;
        }

        public String getLink_place_in_list() {
            return link_place_in_list;
        }

        public String getWeb_link() {
            return web_link;
        }

        public WebLinkIconEntity getWeb_link_icon() {
            return web_link_icon;
        }

        public static class WebLinkIconEntity {
            private String src;
            private String alt;

            public void setSrc(String src) {
                this.src = src;
            }

            public void setAlt(String alt) {
                this.alt = alt;
            }

            public String getSrc() {
                return src;
            }

            public String getAlt() {
                return alt;
            }
        }
    }
}

}

this is the result String i am trying to parse to the java object

{
  "links": [
    {
      "link": {
        "title": "ראשי",
        "link_place_in_list": "1",
        "web_link": "http://app.bsn.co.il/node/9058",
        "web_link_icon": {
          "src": "http://bsn.co.il/sites/default/files/7b258ff5-819c-4de4-a6c9-482ecc847a0a.Png",
          "alt": ""
        }
      }
    }

  ]
}

2 Answers 2

1

The json structure looks OK. Perhaps the problem is that you are using hebrew String: "title": "ראשי", And maybe you are using an old version of Gson jar? Anyway, try to change the hebrew string to english one and recheck. It worked on my machine, with hebrew as well.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Hebrew language was my problem. It works fine with only english. What gson version are you using ?
1

Your json string seems corrent but i have a doubt on your way of parsing your data cause gson parse wont work on complexe field unless you use a custom deSerializer otherwise you can try to use the code below

Gson gson = new Gson();
Type type = new TypeToken<ArrayList<LinksEntity>>(){}.getType()
data = gson.fromJson(result.get("links").getAsJsonArray(), type);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.