如何使用齐射来制作复杂jsonarray数据的模型类

时间:2018-06-05 07:06:11

标签: android

下面我提供了我的代码,我从服务器获取整个数据,但由于多个数组,我无法在模型类中保存数据。请建议我如何使用Volley + JSON而不是GSON来执行此操作。

if (ResponseCode == 1) {

    JSONObject detailObject = jsonObject.getJSONObject("Detail");
    String firstName = detailObject.getString("FirstName");
    String lasttName = detailObject.getString("LastName");

    JSONArray ConstQuestionsArray = detailObject.getJSONArray("ConstQuestions");
    for (int i = 0; i < ConstQuestionsArray.length(); i++) {
        JSONObject object1 = ConstQuestionsArray.getJSONObject(i);
        Log.e(TAG, "ConstQuestionsArray :: " + ConstQuestionsArray);

        String QuestionSetId = object1.getString("QuestionSetId");
        String PathwayId = object1.getString("PathwayId");
        String UserId = object1.getString("UserId");
        String RuleId = object1.getString("RuleId");

        JSONArray QuestionsArray = object1.getJSONArray("Questions");
        for (int j = 0; j < QuestionsArray.length(); j++) {
            JSONObject object2 = QuestionsArray.getJSONObject(j);

            String QuestionId = object2.getString("QuestionId");
            String QuestionName = object2.getString("QuestionName");
            Log.e("QuestionId", QuestionId);
            Log.e("question name", QuestionName);
            JSONArray choicelistArray = object2.getJSONArray("choicelist");
            for (int k = 0; k > choicelistArray.length(); k++) {

                JSONObject object3 = choicelistArray.getJSONObject(k);
                //Log.e(TAG, "choicelistArray :: " + choicelistArray);
                String choiceId = object3.getString("choiceId");
                String ChoiceName = object3.getString("ChoiceName");
                Log.e("choiceId", choiceId);
                Log.e("choice_name", ChoiceName);

            }
        }
    }
}

0 个答案:

没有答案