2017-01-10 9 views
0

レイアウトjsonを統合するためにretrofitライブラリを使用しようとしていますが、テキストビューにデータを設定しようとすると何も返されません。Retrofit jsonを使用して空のテキストを返します

インタフェース

public interface Item_Testing { 
    @GET("datingconvay/api.php?action=users&facebook_id=368008520231015") 
    Call<Recycler_Adapter> responserecycler(); 

    @GET("datingconvay/api.php?action=profile&facebook_id=368008520231016") 
    Call<Single_Profile> singleprofile(); 
} 

SingleProfile.java

public class Single_Profile { 
    @SerializedName("profile") 
    JSONObject profile; 
    @SerializedName("username") 
    String username; 
    @SerializedName("country") 
    String country; 
    @SerializedName("religion") 
    String religion; 
    @SerializedName("nationality") 
    String nationality; 

} 

ProfileView.java

public class Icon_Test extends AppCompatActivity { 
    @BindView(R.id.username) 
    TextView username; 
    @BindView(R.id.ctry) 
    TextView ctry; 
    @BindView(R.id.religion) 
    TextView religion; 
    @BindView(R.id.national) 
    TextView national; 
    String log = "main"; 

    @Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate())); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.icon_test); 
     ButterKnife.bind(this); 
     Retrofit singfit = new Retrofit.Builder().baseUrl("http://sampletemplates.co.in/").addConverterFactory(GsonConverterFactory.create()).build(); 
     Item_Testing singitem=singfit.create(Item_Testing.class); 
     Call<Single_Profile> callsingle=singitem.singleprofile(); 
     callsingle.enqueue(new Callback<Single_Profile>() { 
      @Override 
      public void onResponse(Call<Single_Profile> call, Response<Single_Profile> response) { 
       Toast.makeText(Icon_Test.this,"This method is called", Toast.LENGTH_SHORT).show(); 
       Single_Profile singprofile=response.body(); 
       username.setText(singprofile.username); 
      } 

      @Override 
      public void onFailure(Call<Single_Profile> call, Throwable t) { 
       Log.d(log,t.toString()); 
      } 
     }); 


    } 
} 

MyJSONData

{ 
    "profile": { 
     "id": "4", 
     "facebook_id": "368008520231016", 
     "username": "Raja", 
     "country": "India", 
     "religion": "Hindu", 
     "nationality": "Indian", 
     "gender": "Male", 
     "dob": "1989-06-12", 
     "email": "[email protected]", 
     "profile_pic": [ 
      "http://sampletemplates.net.in/datingconvay/uploads/keerthi2.jpg" 
     ], 
     "device_name": "ios", 
     "device_token": "", 
     "villege": "Kakinada", 
     "ifeel": "", 
     "description": "", 
     "lat": "0", 
     "lng": "0", 
     "platform": "" 
    }, 
    "status": "Success" 
} 

答えて

1

インターフェイスでSingle_Profileを文字列に変更すると、応答を印刷できます

@GET("datingconvay/api.php?action=profile&facebook_id=368008520231016") 
     Call<String> singleprofile(); 

callsingle.enqueue(new Callback<String>() { 
      @Override 
      public void onResponse(Call<String> call, Response<String> response) { 
       Log.d("Response",response.body); 
      } 

      @Override 
      public void onFailure(Call<String> call, Throwable t) { 
       Log.d(log,t.toString()); 
      } 
     }); 
関連する問題