2016-01-21 23 views
0

這裏包含的TextView JSON數據varible是我的代碼:我如何通過使用改裝

public void jsontesting(){ 
    //While the app fetched data we are displaying a progress dialog 

    //Creating a rest adapter 
     RestAdapter restAdapter = (RestAdapter) new RestAdapter.Builder().setEndpoint(getResources().getString(R.string.master_url)).build(); 


    //Creating an object of our api interface 
      LatlngAPI api = restAdapter.create(LatlngAPI.class); 

      //Defining the method 
      api.get_doctor("10",new retrofit.Callback<LatlngOperations>(){ 
      @Override 
      public void success(LatlngOperations res, Response response) { 

       for(Doctor d:res){ 
       Log.d("id", d.getClinic_id()); 
       //} 
       /*if (!res.isError()) {*/ 
       String id=d.getId().toString(); 
       Log.d("id", d.getId()); 
       String clinic_id=d.getClinic_id().toString(); 
       String clinic_name=d.getClinic_name().toString(); 
       String Name=d.getName().toString(); 
       String Degree=d.getDegree().toString(); 
       String Degree_name=d.getDegree_name().toString(); 
       String Experience=d.getExperience().toString(); 
       String Consultation=d.getConsultation().toString(); 
       String Insurances_accepted=d.getInsurances_accepted().toString(); 
       String Image=d.getImage().toString(); 
       String Clinic_image=d.getClinic_image().toString(); 
       String Address=d.getAddress().toString(); 
       String Address2=d.getAddress2().toString(); 
       String Location=d.getLocation().toString(); 

       } else { 
          Toast.makeText(

MainActivity.this,"No Record found", 
           Toast.LENGTH_SHORT).show(); 

      } 
     } 

     @Override 
     public void failure(RetrofitError error) { 
    //    dismiss_dialog(); 
      Log.d("Error", error.toString()); 
        /*Toast.makeText(LoginActivity.this, R.string.retrofit_error, 
          Toast.LENGTH_SHORT).show();*/ 
     } 
     }); 
    } 
+2

並不清楚你的要求。 – Rohit5k2

回答

0

您可以將用戶GSON LIB從對象獲取JSON文本

Gson gson = new Gson(); 
String jsonStr = gson.toJson(object,Object.class); 
textview.settext(jsonStr); 
+0

我的意思是,從上面的代碼假設String id = d.getId()從json獲取id,我想在textview上設置String id,那麼我該怎麼做呢? –

+0

gson沒有幫助me.please幫助我。我不能夠弄清楚如何獲得textview中的數據 –

+0

textview.setTex(d.getId()); –