【问题标题】:How can i get data from array in array retrofit2如何从数组 Retrofit2 中的数组中获取数据
【发布时间】:2016-12-16 15:05:35
【问题描述】:

请收下这份参考

想要让约会数组列表膨胀列表视图,我到达了 call_detail 但我怎样才能使用retrofit2 gsonConverter 获得约会数组

{
"patient":{},
"medicine":[
],
"call_detail":[
{
"created_on":"2016-01-22 06:06:00",
"call_type":"",
"rbs":"10",
"temp":"",
"provisional_diagnosis":"yes",
"follow_up_call_schedule":"",
"follow_up_call_date":"1970-01-01",
"reports":[
],
"medicalreference":[
],
"services_comment":"",
"health_consultation":"",
"appointment":[
{
"doctor_id":"28",
"clinic":"",
"hospital":"Shwe Nyaung Pin specialist ",
"name":"Dr.Nyein Mon Yu",
"app_date":"2016-01-21",
"app_time":"1:00 AM TO 1:00 AM"
}
]
}
],
"status":"true"
}

【问题讨论】:

  • 尝试我的答案以获取约会的数组详细信息
  • 我正在使用带有 gsonConverter 的 retrofit2... response.body().getCallDetail() 我得到了 call_detail 数组。但是 call_detail 中的 i 约会数组..

标签: android json multidimensional-array retrofit2


【解决方案1】:

试试这个..

    try {
        JSONObject jsonObject=new JSONObject(response);

        JSONArray jsonArray=jsonObject.getJSONArray("call_detail");

        for(int i=0;i<jsonArray.length();i++)
        {
            JSONObject jsonObjectCall=jsonArray.getJSONObject(i);

            JSONArray jsonArrayAppointment=jsonObjectCall.getJSONArray("appointment");

            for (int j=0;j<jsonArrayAppointment.length();j++)
            {
                JSONObject jsonObjectApp=jsonArrayAppointment.getJSONObject(j);

                String doctor_id=jsonObjectApp.getString("doctor_id");
                String clinic=jsonObjectApp.getString("clinic");
                String hospital=jsonObjectApp.getString("hospital");
                String name=jsonObjectApp.getString("name");
                String app_date=jsonObjectApp.getString("app_date");
                String app_time=jsonObjectApp.getString("app_time");

                System.out.println("doctor_id"+doctor_id);

            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

【讨论】:

    【解决方案2】:

    要获取约会数组,请尝试以下代码。这里 jsonString 是你给定的 json 有问题:

        try {
                JSONObject jsonObject=new JSONObject(jsonString);
                JSONArray appointmentArray=jsonObject.getJSONArray("call_detail").getJSONObject(0).getJSONArray("appointment");
                Log.d("appointmentArray",appointmentArray.toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
    

    【讨论】:

    • 我正在使用带有 gsonConverter 的 retrofit2... response.body().getCallDetail() 我得到了 call_detail 数组。但是 call_detail 中的 i 约会数组..
    猜你喜欢
    • 2022-11-03
    • 2021-06-05
    • 2016-02-01
    • 2021-01-19
    • 2020-08-18
    • 1970-01-01
    • 2021-11-04
    • 2020-04-01
    相关资源
    最近更新 更多