0

I have to consume an API RESTful web service. At the moment I have to deal with a JSON object which looks like:

{
  "success":true,
  "error":"",
  "message":"",
  "data":[
     ["USD","US Dollar","11,696", "connected"],
     ["EUR","Euro","10,733","connected"]
  ]
}

And this is the class I use in general to hold most endpoints of this web service:

public class Response {
    public boolean success;
    private String error;
    private String message;        
    private List<Map<Integer, Array>> data;

    public String getError() {
        return this.error;
    }

    public String getMessage() {
        return this.message;
    }

    public Map<Integer,Array> getData() {
        return this.data.get(0);
    }
}

When running, app crashes with:

Could not read JSON: Can not deserialize instance of java.util.LinkedHashMap 
     out of START_ARRAY token
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
Jhon Zunda
  • 63
  • 11

2 Answers2

0

We need to change the type of 'data' from

List<Map<Integer, Array>>

to

List<List<String>>
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
  • Thank you for you interest, but seems that it doesnt work. I get now: Could not read JSON: Unrecognized field "data" ... Indeed, the 2nd level in the nested array is not a List of Strings, but rather an array with int as key and an array of strings as value .. – Jhon Zunda Dec 23 '15 at 18:14
0

I ended up figuring out that what i need is just:

private List<ArrayList<String>> data;

Worked like a charm.

Jhon Zunda
  • 63
  • 11