2016-08-10 100 views
1

請把這參考如何從陣列獲取的數據在陣列retrofit2

想約會的ArrayList膨脹的ListView,我伸手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" 
} 
+0

嘗試我的回答得到任命 –

+0

我使用retrofit2與gsonConverter的陣列詳細... response.body()getCallDetail()我得到call_detail陣列。但我預約數組是在call_detail .. –

回答

0

試試這個......

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(); 
    } 
+0

謝謝,但它不能幫助我 –

+0

顯示您的代碼..你試試 –

0

要獲得約會數組,請嘗試下面的代碼。這裏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(); 
     } 
+0

我使用retrofit2與gsonConverter ... response.body()。getCallDetail( )我得到了call_detail數組。 但我在call_detail中的約會數組.. –