[英]how do i pass varible containing json data in textview using retrofit
这是我的代码:
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();*/
}
});
}
您可以使用Gson lib从对象获取json文本
Gson gson = new Gson();
String jsonStr = gson.toJson(object,Object.class);
textview.settext(jsonStr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.