如何使用改造在textview中传递包含json数据的varible

时间:2016-01-21 08:38:05

标签: java android

这是我的代码:

  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();*/
        }
      });
    }

1 个答案:

答案 0 :(得分:0)

您可以使用Gson lib从对象

获取json文本
Gson gson = new Gson();  
String jsonStr = gson.toJson(object,Object.class);
textview.settext(jsonStr);