-1

This is the string i receive is a validate json by jsonlint String decodedCookie = URLDecoder.decode(myCookie.getValue(), "UTF-8"); Gson g = new Gson();

here what that string look like

{
    "urlAW": "http://www.google.com",
    "urlApi": "http://www.google.com",
    "lang": "en",
    "infoComplete": "{\"id\":\"569\",\"status\":\"START\"}",
    "isApp": false,
    "isActive": false
}

Infos = g.fromJson(decodedCookie, Infos.class);

each time i try to parse it fail at infoComplete

given the error java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1

but InfoComplete.class only has 2 fields id and status with getter and setter

not sure what i am missing to make it work. Any help will be appreciate.

Infos class look like this

public class Infos {
    private String urlAW;
    private String urlApi;   
    private String lang;
    private InfoComplete infoComplete;
    private boolean isApp;
    private boolean isActive;

    public String getUrlAW() {
        return urlAW;
    }

    public void setUrlAW(String urlAW) {
        this.urlAW = urlAW;
    }

    public String getUrlApi() {
        return urlApi;
    }

    public void setUrlApi(String urlApi) {
        this.urlApi = urlApi;
    }

    public String getLang() {
        return langue;
    }

    public void setLang(String lang) {
        this.lang = lang;
    }

    public InfoComplete getInfoComplete() {
        return infoComplete;
    }

    public void setInfoComplete(InfoComplete infoComplete) {
        this.infoComplete = infoComplete;
    }

    public boolean isApp() {
        return isApp;
    }

    public void setApp(boolean app) {
        isApp = app;
    }

    public boolean isActive() {
        return isActive;
    }

    public void setActive(boolean active) {
        isActive = active;
    }


    @Override
    public String toString() {
        return "Infos{" +
                "urlAW='" + urlAW + '\'' +
                ", urlApi='" + urlApi + '\'' +
                ", lang='" + lang + '\'' +
                ", infoComplete='" + infoComplete + '\'' +
                ", isApp=" + isApp +
                ", isActive=" + isActive +
                '}';
    }
}
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
DarkVision
  • 1,373
  • 3
  • 20
  • 33
  • This: `Infos = g.fromJson(decodedCookie, Infos.class);` isn't valid Java – Hovercraft Full Of Eels Dec 28 '17 at 22:25
  • `"infoComplete": "{\"id\":\"569\",\"status\":\"START\"}"` is a String and it's expected a JSONObject. – Ele Dec 28 '17 at 22:26
  • Well, infoComplete is a string in your JSON. Not an object. So the exception is quite normal. A JSON parser is not magically recursive: it won't parse string values of your JSON. – JB Nizet Dec 28 '17 at 22:26

1 Answers1

0

The problem here is the type of infoComplete

"infoComplete": "{\"id\":\"569\",\"status\":\"START\"}"

Try to check the response or you can convert that string into a valid JSONObject:

{
  "urlAW": "http://www.google.com",
  "urlApi": "http://www.google.com",
  "lang": "en",
  "infoComplete": {
    "id": "569",
    "status": "START"
  },
  "isApp": false,
  "isActive": false
}
Ele
  • 33,468
  • 7
  • 37
  • 75