在Retrofit版本2.0中获取json异常,并在电子邮件地址中添加特殊字符“-”和“ _”

时间:2018-11-29 14:44:18

标签: android retrofit2 special-characters

当用户尝试注册时,我无法传递任何字符为- _ 的电子邮件地址。这是改造的定义:

@Headers(API_KEY)
@FormUrlEncoded
@POST("signInUser")
Call<HttpResponseModel> signInUser(@Field(value ="userEmail", encoded = true) String userEmail,
                                   @Field("userId") String userId,
                                   @Field("userPasswordHash") String pwHash);

和我的方法调用:

Call<HttpResponseModel> signInUser = retrofitApiInterface.signInUser(userEmail, userId, passWord);

    signInUser.enqueue(new Callback<HttpResponseModel>() {
        @Override
        public void onResponse(@NonNull Call<HttpResponseModel> call, @NonNull Response<HttpResponseModel> response) {
           .....  //my implemenation

        }

        @Override
        public void onFailure(@NonNull Call<HttpResponseModel> call, @NonNull Throwable t) {
            listener.onFailure(); //exception gets thrown here
        }
    });
}

我收到的错误消息是:

  

com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_OBJECT,但在第1行第2列路径$ BEGIN_ARRAY是

例如,抛出异常的电子邮件:我将使用的电子邮件为:my-name@email.com。

如果电子邮件地址为myname@email.com,则可以正常工作

通话值:

encodedNames = {Collections$UnmodifiableRandomAccessList@12120}  size = 3
0 = "userEmail"
1 = "userId"
2 = "userPasswordHash"
encodedValues = {Collections$UnmodifiableRandomAccessList@12121}  size = 3
0 = "my-name%40email.com"
1 = ""
2 = "mypassword"

0 个答案:

没有答案
相关问题