2016-01-21 50 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()); –