2016-08-23 3 views
0

ログインに問題があります。私はネットからいくつかの例を試しましたが、何も私のために働きました。メールアドレスとパスワードを使用してログイン後の更新

JSON

{ 
    "responseCode":1, 
    "responseCodeText":"ok", 
    "response": 
    { 
     "id":1234, 
     "email":"[email protected]", 
     "name":"name", 
     "lastname":"lastname", 
     "properties":[ 
      //... 
     ], 
     "rights":"admin", 
     "photo":"url", 
     "favorites": 
     [ 
      //... 
     ], 
     "token":"token" 
    } 
} 

私はhttp://www.jsonschema2pojo.org/からモデルクラスを作成しているので、それはOKでなければなりません。活動の

インタフェース

public interface LoginInterface { 

    @POST("login/{email}/{password}") 
    Call<UserResponse> login(@Path("email") String email, @Path("password") String password); 
} 

コール私が持っている

public void serviceInit() { 
     String email = edEmail.getText().toString(); 
     String password = edPassword.getText().toString(); 

     FactoryAPI.getInstanceLogin().login(email, password).enqueue(new Callback<UserResponse>() { 
      @Override 
      public void onResponse(Call<UserResponse> call, Response<UserResponse> response) { 
       if(response.isSuccessful()) { 
        Intent intent = new Intent(getContext(), AccountActivity.class); 
        startActivity(intent); 
       } 
       //TODO: load from sharedPreferences 
      } 

      @Override 
      public void onFailure(Call<UserResponse> call, Throwable t) { 
       Log.e("error", "points not loaded"); 
      } 
     }); 
    } 

ERROR

responseCodeText: "属性エラー"

私はサーバーからリクエストを受け取りました。私のメールアドレスとパスワードを助け

+0

あなたはどのようなエラーを取得していますか? –

+0

あなたはどんな問題に直面していますか? –

+0

あなたの質問を編集して、エラーの説明を含めてください。 – theFunkyEngineer

答えて

0

ため

おかげでJSONを内にマッピングされることをお使いの応答クラスはJSONとして正確な構造と属性を持っている必要がありますGETではなく、POSTです。

したがって、UserResponseには、すべてのフィールドが含まれている必要があります。このような何か:

public class UserResponseDTO { 
    public int responseCode; 
    public String responseCodeText; 
    public UserDTO response; 
} 

public class UserDTO { 
    public int id; 
    public String email; 
    public String name; 
    public String lastname; 
    public List<PropertyDTO> properties; 
    public String rights; 
    public String photo; 
    public List<FavoriteDTO> favorites; 
    public String token; 
} 
+0

この問題は '@ FormUrlEncoded'で見つかった。出来ますか?それは私が追加したもので、今は効いている。 – Stepan

+0

@POST( "login/{email}/{password}") 'のようなエンドポイントを指定していませんか? あなたの投稿を編集してもよろしいですか? – raxelsson

0

問題があった:

@FormUrlEncoded 
@POST("login") 
Call<UserResponse> login(@Field("email") String email, @Field("password") String password); 
関連する問題