1

I want convert Json string to List by GSON library.

 public <T> List<T> getModelList(String jsonStr, Class<T> type) {
        Type listType = new TypeToken<ArrayList<T>>(){}.getType();
        List<T> yourClassList = new Gson().fromJson(jsonStr, listType);
        return yourClassList;
    }

and I call

List<CallDetail> callDetails = Converter.me().getModelList(responseMessage.getResult(), CallDetail.class);

But I get List with com.google.gson.internal.LinkedTreeMap object but I need List<CallDetail>

Json string fragment

"result": "[{\"servedimei\":\"3579330679481801\",\"тип сетевого события\":\"Исходящий голос\",\"время начала события\":\"2016-01-01 19:33:10.0\"

POJO

public class CallDetail {

    private String servedimei;
    @SerializedName("тип сетевого события")
    private String type;
    @SerializedName("время начала события")
    private String starttime;
    @SerializedName("вызывающий абонент")
    private String src;
    @SerializedName("вызываемый абонент")
    private String dest;
    @SerializedName("длительность")
    private String duration;
    @SerializedName("базовая станция")
    private String bs;
    private String lac;
    private String ci;
user5620472
  • 2,722
  • 8
  • 44
  • 97

1 Answers1

0

It's very simple from logs. JSON string contains result field that contains array and GSON treat it as Map. You need one more class to get the desired result.

class CallDetailResult {
        List<CallDetail> result;
        // getter and setter
}

// how to use GSON here to get the desired result
CallDetailResult  result = new Gson().fromJson(jsonStr, CallDetailResult.class);
List<CallDetail> list = result.getResult();

Read more at www.json.org

enter image description here

enter image description here

Braj
  • 46,415
  • 5
  • 60
  • 76
  • your JSON string doesn't start with `[...]` that represents array. you have to pass just the string of `result` field. – Braj Jan 22 '16 at 11:28