Gson - 将表格json(List内列表)转换为List<> Android的

时间:2015-02-24 10:56:56

标签: android json gson

昨天我管理了如何将json转换为列表<>,json文件非常简单。

现在我有一个子文件,里面有一个List列表就在这里:

<

这里是我的代码:

listq = new ArrayList<Survey>();

    try {
        result =    new RequestTask().execute("urveys/current?owner=ofc&user=yasser&category=-1").get();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
      GsonBuilder gsonb = new GsonBuilder();
       Gson gson = gsonb.create();
       listq = gson.fromJson(result,  Surveyentity.class).List;

       Toast.makeText(Questions.this, "result", Toast.LENGTH_SHORT).show();
}

我的班级调查:

public class Survey {

String IdQuestion;
String Label;
List<Reponse> Reponses;
public String getIdQuestion() {
    return IdQuestion;
}
public void setIdQuestion(String idQuestion) {
    IdQuestion = idQuestion;
}
public String getLabel() {
    return Label;
}
public void setLabel(String label) {
    Label = label;
}
public List<Reponse> getReponses() {
    return Reponses;
}
public void setReponses(List<Reponse> reponses) {
    Reponses = reponses;
}

我的班级回复:

public class Reponse {

String IdProposition;
String Label;
String Format;
String url;
String Points;
String Next;
String Comment;
String Selected;
public String getIdProposition() {
    return IdProposition;
}
public void setIdProposition(String idProposition) {
    IdProposition = idProposition;
}
.............

和我的班级调查实体:

public class Surveyentity {

 public List<Survey> List;

}

这有什么问题?

1 个答案:

答案 0 :(得分:0)

更新您的Survey课程

public class Survey {

String IdQuestion;
String Label;
List<Reponse> List; // it should be List not Responses
public String getIdQuestion() {
    return IdQuestion;
}
public void setIdQuestion(String idQuestion) {
    IdQuestion = idQuestion;
}
public String getLabel() {
    return Label;
}
public void setLabel(String label) {
    Label = label;
}
public List<Reponse> getReponses() {
    return Reponses;
}
public void setReponses(List<Reponse> reponses) {
    Reponses = reponses;
}