2016-10-26 20 views
0

私はポストのための改修を実施する際に、このフォーマットAndroidの改修簡単なチェックと印刷結果

{"result":"1"} 

でサーバーとプリント結果によって確認されたuserMobileNumberを投稿し、私はNo Retrofit annotation foundエラー

を取得した結果を得ます

チェックモバイルモデル:

public class CheckMobile { 
    private String userMobileNumber; 

    public String getUserMobileNumber() { 
     return userMobileNumber; 
    } 

    public void setUserMobileNumber(String userMobileNumber) { 
     this.userMobileNumber = userMobileNumber; 
    } 
} 

サービス:

public interface TestService { 
    @POST("rst_checkmobile") 
    Call<CheckMobile> checkMobile(String body); 

    public static final Retrofit retrofit = new Retrofit.Builder() 
      .baseUrl(ClientConfigs.REST_API_BASE_URL) 
      .addConverterFactory(GsonConverterFactory.create()) 
      .build(); 
} 

ポストと取得結果:

@OnClick(R.id.request_create_account) 
public void RequestCreateAccount(View view) { 
    String userMobileNumber = user_mobile_number.getText().toString().trim(); 
    if (userMobileNumber.length() > 1) { 
     TestService testService = TestService.retrofit.create(TestService.class); 
     final Call<CheckMobile> call = TestService.checkMobile(userMobileNumber); 

     call.enqueue(new Callback<CheckMobile>() { 
      @Override 
      public void onResponse(Call<CheckMobile> call, Response<CheckMobile> response) { 
       Log.e("OK: ", response.body().toString()); 
      } 

      @Override 
      public void onFailure(Call<CheckMobile> call, Throwable t) { 
       Log.e("ERROR: ", t.getMessage()); 
      } 
     }); 
    } 
} 

答えて

0

は、私はあなたの問題を理解します。 、

import javax.annotation.Generated; 
import com.google.gson.annotations.Expose; 
import com.google.gson.annotations.SerializedName; 

public class CheckMobile{ 

@SerializedName("result") 
@Expose 
private String result; 


public String getResult() { 
return result; 
} 

public void setResult(String result) { 
this.result = result; 
} 

} 

そして、あなたのRequestCreateAccount方法で

call.enqueue(new Callback<CheckMobile>() { 
      @Override 
      public void onResponse(Call<CheckMobile> call, Response<CheckMobile> response) { 
       Log.e("OK: ", response.body().getResult()); 
      } 

      @Override 
      public void onFailure(Call<CheckMobile> call, Throwable t) { 
       Log.e("ERROR: ", t.getMessage()); 
      } 
     }); 

それを試してみて、それが働いされているかどうか私に教えて:あなたは、POJOとしてモデルクラスを作成する必要があります。エラーログを投稿しない場合。

0

あなたの名前を呼んでください。 それを使用したい場合は、新しいフィールドをCheckMobile.classに追加してください。

@SerializedName("result")private String result;