我是Android新手,正在開發具有服務器端功能的應用程序。我以JSON格式獲得響應。從JSON字符串中獲取json對象
我的迴應如圖所示。
我知道如何使用Volley解析json,但我不知道使用GSON來解析json。我的應用程序的以前的代碼是由其他人編寫的。現在我必須完成這個代碼。但我不知道他是如何從JSON字符串獲取數據的。我需要JSON數組在不同的活動。陣列響應:
下面是我的一些代碼卡扣。
代碼適配器活動一個
topicListAdapter = new TopicListAdapter(TopicActivity.this,
myCourseListMain. getCourseArrayList().get(Integer.parseInt(course_position)).
getTopicListMain().getTopicDetailsArrayList(), flag);
listAlltopics.setAdapter(topicListAdapter);
中,我得到了主題
這裏的列表是次活動列表適配器
lessionListAdapter = new LessionListAdapter(LessionActivity.this,
myCourseListMain. getCourseArrayList(). get(Integer.parseInt(course_position)).
getTopicListMain().getTopicDetailsArrayList().get(Integer.parseInt(topic_position)).getLessionArrayList(), flag);
代碼這段代碼我得到的數組在第二次活動中的激情
現在我想要在t赫爾德活動,但我不知道如何得到它。 這裏是我試過
lessionListAdapter = new DummyAdapter(DummyTopicList.this,
myCourseListMain . getCourseArrayList(). get(Integer.parseInt(course_position)).
getTopicListMain() . getTopicDetailsArrayList() .get(Integer.parseInt(topic_position)).
getLessionLIstMain() .getLessionLIstDetailArrayList().get(Integer.parseInt(lession_position)). , flag);
listAlllessions.setAdapter(lessionListAdapter);
這裏有一些其他類這有助於你瞭解
public class MyCourseListMain {
@SerializedName("data")
private ArrayList<Course> courseArrayList;
public ArrayList<Course> getCourseArrayList() {
return courseArrayList;
}
public void setCourseArrayList(ArrayList<Course> courseArrayList) {
this.courseArrayList = courseArrayList;
}
}
類課程
public class Course {
@SerializedName("img")
private String img;
@SerializedName("title")
private String title;
@SerializedName("institute_id")
private String institute_id;
@SerializedName("institute_name")
private String institute_name;
@SerializedName("expired")
private String expired;
@SerializedName("status")
private String status;
@SerializedName("subscribe_box")
private String subscribe_box;
@SerializedName("expire_on")
private String expire_on;
@SerializedName("item_id")
private String item_id;
@SerializedName("rated")
private String rated;
private TopicListMain topicListMain;
public String getRated() {
return rated;
}
public void setRated(String rated) {
this.rated = rated;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getInstitute_id() {
return institute_id;
}
public void setInstitute_id(String institute_id) {
this.institute_id = institute_id;
}
public String getInstitute_name() {
return institute_name;
}
public void setInstitute_name(String institute_name) {
this.institute_name = institute_name;
}
public String getExpired() {
return expired;
}
public void setExpired(String expired) {
this.expired = expired;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getSubscribe_box() {
return subscribe_box;
}
public void setSubscribe_box(String subscribe_box) {
this.subscribe_box = subscribe_box;
}
public String getExpire_on() {
return expire_on;
}
public void setExpire_on(String expire_on) {
this.expire_on = expire_on;
}
public String getItem_id() {
return item_id;
}
public void setItem_id(String item_id) {
this.item_id = item_id;
}
public TopicListMain getTopicListMain() {
return topicListMain;
}
public void setTopicListMain(TopicListMain topicListMain) {
this.topicListMain = topicListMain; } }
類topiclist_main
public class TopicListMain {
@SerializedName("data")
private ArrayList<TopicDetails> topicDetailsArrayList;
public ArrayList<TopicDetails> getTopicDetailsArrayList() {
return topicDetailsArrayList;
}
public void setTopicDetailsArrayList(ArrayList<TopicDetails> topicDetailsArrayList) {
this.topicDetailsArrayList = topicDetailsArrayList; }}
類話題的細節
public class TopicDetails
{
@SerializedName("topic_id")
private String topic_id;
@SerializedName("title")
private String title;
@SerializedName("locked")
private String locked;
@SerializedName("lessons")
private ArrayList<Lession> lessionArrayList;
private LessionLIstMain lessionLIstMain;
public LessionLIstMain getLessionLIstMain() {
return lessionLIstMain;
}
public void setLessionLIstMain(LessionLIstMain lessionLIstMain) {
this.lessionLIstMain = lessionLIstMain;
}
public String getTopic_id() {
return topic_id;
}
public void setTopic_id(String topic_id) {
this.topic_id = topic_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLocked() {
return locked;
}
public void setLocked(String locked) {
this.locked = locked;
}
public ArrayList<Lession> getLessionArrayList() {
return lessionArrayList;
}
public void setLessionArrayList(ArrayList<Lession> lessionArrayList) {
this.lessionArrayList = lessionArrayList; }}
你到底想要什麼?你想通過Gson解析圖像中的json嗎? –
這個問題包含很多乞討,txtspk和拼寫錯誤,並不代表我們希望在問題中看到很好的努力。如果您使用手機發布信息,當您在此發佈信息時,是否可以使用筆記本電腦或PC? – halfer
請閱讀[在什麼情況下我可以添加「緊急」或其他類似的短語到我的問題,以獲得更快的答案?](https://meta.stackoverflow。com/q/326569) - 總結是這不是解決志願者問題的理想方法,而且可能對獲得答案起反作用。請不要將這添加到您的問題。 – halfer