解析时遇到麻烦。我有一个Json格式的数组列表。
{
"details": [
{
"question_id": "1",
"Questions": "QUESTION1",
"Marks": "10"
},
{
"question_id": "2",
"Questions": "QUESTION2",
"Marks": "10"
},
{
"question_id": "3",
"Questions": "QUESTION3",
"Marks": "10"
}
],
"status_code": 1,
"status_description": "Successsfull."
}
现在,从这个JSONARRAY中,我需要将每个对象的question_id发送到下一个活动,在该活动中,我需要在URL中发送question_id以从API获取下一个问题。
我的问题是如何在另一个活动中一个一个地发送question_id。
实际上,这是一个QUIZ APP。
最佳答案
public class McqQuestionBeanCheck implements Serializable {
private int question_id;
private String questions,marks;
public int getQuestion_id() {
return question_id;
}
public void setQuestion_id(int question_id) {
this.question_id = question_id;
}
public String getQuestions() {
return questions;
}
public void setQuestions(String questions) {
this.questions = questions;
}
public String getMarks() {
return marks;
}
public void setMarks(String marks) {
this.marks = marks;
}
}
使用此方法进行解析...
public ArrayList<McqQuestionBeanCheck> mcqQuestionParsingCheck(String response) {
ArrayList<McqQuestionBeanCheck> questions = new ArrayList<McqQuestionBeanCheck>();
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray questionsArray = jsonObject.getJSONArray("details");
for (int i = 0; i < questionsArray.length(); i++) {
JSONObject questionObject = questionsArray.getJSONObject(i);
McqQuestionBeanCheck question = new McqQuestionBeanCheck();
question.setQuestion_id(questionObject.getInt("question_id"));
question.setQuestions(questionObject.getString("Questions"));
question.setMarks(questionObject.getString("Marks"));
questions.add(question);
}
} catch (JSONException e) {
e.printStackTrace();
}
return questions;
}