我正在尝试为我的应用程序创建忘记密码脚本。当我运行我的apk并尝试保留我的密码时,我得到了一个错误,上面写着使用JsonReader。setLenient(true)要在第1行第1列路径$Error处接受格式错误的JSON,我的apk中一切正常,我可以登录、注销或注册,但当我重置密码时,我得到了JsonReader。设置宽容(真)错误。我的apk json正在工作,它是正确的。请帮帮我。我在分享我的代码。
{
"operation":"resPassReq",
"user":{
"email":"name@example.com"
}
}
如果请求成功,响应将类似于,
{
"result": "success",
"message": "Check your mail for reset password code."
}
对于完成密码重置过程,请求类似于,
{
"operation":"resPass",
"user":{
"email":"name@example.com",
"code":"bcfqa3",
"password":"rjamalw"
}
}
如果请求成功,响应将类似于,
{
"result": "success",
"message": "Password Changed Successfully"
}
重置密码片段。JAVA
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ResetPasswordFragment extends Fragment implements View.OnClickListener{
private AppCompatButton btn_reset;
private EditText et_email,et_code,et_password;
private TextView tv_timer;
private ProgressBar progress;
private boolean isResetInitiated = false;
private String email;
private CountDownTimer countDownTimer;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_password_reset,container,false);
initViews(view);
return view;
}
private void initViews(View view){
btn_reset = (AppCompatButton)view.findViewById(R.id.btn_reset);
tv_timer = (TextView)view.findViewById(R.id.timer);
et_code = (EditText)view.findViewById(R.id.et_code);
et_email = (EditText)view.findViewById(R.id.et_email);
et_password = (EditText)view.findViewById(R.id.et_password);
et_password.setVisibility(View.GONE);
et_code.setVisibility(View.GONE);
tv_timer.setVisibility(View.GONE);
btn_reset.setOnClickListener(this);
progress = (ProgressBar)view.findViewById(R.id.progress);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_reset:
if(!isResetInitiated) {
email = et_email.getText().toString();
if (!email.isEmpty()) {
progress.setVisibility(View.VISIBLE);
initiateResetPasswordProcess(email);
} else {
Snackbar.make(getView(), "Fields are empty !", Snackbar.LENGTH_LONG).show();
}
} else {
String code = et_code.getText().toString();
String password = et_password.getText().toString();
if(!code.isEmpty() && !password.isEmpty()){
finishResetPasswordProcess(email,code,password);
} else {
Snackbar.make(getView(), "Fields are empty !", Snackbar.LENGTH_LONG).show();
}
}
break;
}
}
private void initiateResetPasswordProcess(String email){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface requestInterface = retrofit.create(RequestInterface.class);
User user = new User();
user.setEmail(email);
ServerRequest request = new ServerRequest();
request.setOperation(Constants.RESET_PASSWORD_INITIATE);
request.setUser(user);
Call<ServerResponse> response = requestInterface.operation(request);
response.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
ServerResponse resp = response.body();
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
if(resp.getResult().equals(Constants.SUCCESS)){
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
et_email.setVisibility(View.GONE);
et_code.setVisibility(View.VISIBLE);
et_password.setVisibility(View.VISIBLE);
tv_timer.setVisibility(View.VISIBLE);
btn_reset.setText("Change Password");
isResetInitiated = true;
startCountdownTimer();
} else {
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
}
progress.setVisibility(View.INVISIBLE);
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
progress.setVisibility(View.INVISIBLE);
Log.d(Constants.TAG,"failed");
Snackbar.make(getView(), t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
Log.d(Constants.TAG, t.getLocalizedMessage());
}
});
}
private void finishResetPasswordProcess(String email,String code, String password){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface requestInterface = retrofit.create(RequestInterface.class);
User user = new User();
user.setEmail(email);
user.setCode(code);
user.setPassword(password);
ServerRequest request = new ServerRequest();
request.setOperation(Constants.RESET_PASSWORD_FINISH);
request.setUser(user);
Call<ServerResponse> response = requestInterface.operation(request);
response.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
ServerResponse resp = response.body();
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
if(resp.getResult().equals(Constants.SUCCESS)){
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
countDownTimer.cancel();
isResetInitiated = false;
goToLogin();
} else {
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
}
progress.setVisibility(View.INVISIBLE);
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
progress.setVisibility(View.INVISIBLE);
Log.d(Constants.TAG,"failed");
Snackbar.make(getView(), t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
}
});
}
private void startCountdownTimer(){
countDownTimer = new CountDownTimer(120000, 1000) {
public void onTick(long millisUntilFinished) {
tv_timer.setText("Time remaining : " + millisUntilFinished / 1000);
}
public void onFinish() {
Snackbar.make(getView(), "Time Out ! Request again to reset password.", Snackbar.LENGTH_LONG).show();
goToLogin();
}
}.start();
}
private void goToLogin(){
Fragment login = new LoginFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_frame,login);
ft.commit();
}
}
请求nterface.java
public interface RequestInterface {
@POST("req/")
Call<ServerResponse> operation(@Body ServerRequest request);
}
但是当我像下面这样改变我的代码时,一切都很好,但问题是得到了响应
private void initiateResetPasswordProcess(String email){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface requestInterface = retrofit.create(RequestInterface.class);
User user = new User();
user.setEmail(email);
ServerRequest request = new ServerRequest();
request.setOperation(Constants.RESET_PASSWORD_INITIATE);
request.setUser(user);
Call<ServerResponse> response = requestInterface.operation(request);
response.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
ServerResponse resp = response.body();
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
if(resp.getResult().equals(Constants.SUCCESS)){
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
et_email.setVisibility(View.GONE);
et_code.setVisibility(View.VISIBLE);
et_password.setVisibility(View.VISIBLE);
tv_timer.setVisibility(View.VISIBLE);
btn_reset.setText("Change Password");
isResetInitiated = true;
startCountdownTimer();
} else {
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
}
progress.setVisibility(View.INVISIBLE);
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
progress.setVisibility(View.INVISIBLE);
Log.d(Constants.TAG,"failed");
// Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
et_email.setVisibility(View.GONE);
et_code.setVisibility(View.VISIBLE);
et_password.setVisibility(View.VISIBLE);
tv_timer.setVisibility(View.VISIBLE);
btn_reset.setText("Change Password");
isResetInitiated = true;
startCountdownTimer();
// Snackbar.make(getView(), t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
}
});
}
private void finishResetPasswordProcess(String email,String code, String password){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface requestInterface = retrofit.create(RequestInterface.class);
User user = new User();
user.setEmail(email);
user.setCode(code);
user.setPassword(password);
ServerRequest request = new ServerRequest();
request.setOperation(Constants.RESET_PASSWORD_FINISH);
request.setUser(user);
Call<ServerResponse> response = requestInterface.operation(request);
response.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
ServerResponse resp = response.body();
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
if(resp.getResult().equals(Constants.SUCCESS)){
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
countDownTimer.cancel();
isResetInitiated = false;
goToLogin();
} else {
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
}
progress.setVisibility(View.INVISIBLE);
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
progress.setVisibility(View.INVISIBLE);
Log.d(Constants.TAG,"failed");
// Snackbar.make(getView(), t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
countDownTimer.cancel();
isResetInitiated = false;
goToLogin();
}
});
}
服务器响应。JAVA
public class ServerResponse {
private String result;
private String message;
private User user;
public String getResult() {
return result;
}
public String getMessage() {
return message;
}
public User getUser() {
return user;
}
}
服务器请求。JAVA
public class ServerRequest {
private String operation;
private User user;
public void setOperation(String operation) {
this.operation = operation;
}
public void setUser(User user) {
this.user = user;
}
}
在android:JsonReader中,通过改型2上传图像时会出现此错误。setLenient(true)接受第1行第1列路径$Error处格式错误的JSON
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode ==10) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent.createChooser(intent, "Select Image"), 10);
} else {
Toast.makeText(this, "you have dont Permisson", Toast.LENGTH_SHORT).show();
}
return;
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
我曾经面对过这个问题,最终我解决了它。
必须使API中的所有$row在数据库的表中具有相同的名称,如下所示
"book_chalet_id" => $row['book_chalet_id'],
所以表中必须有book\u chalet\u id
列。
private void initiateResetPasswordProcess(String email){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
RequestInterface requestInterface = retrofit.create(RequestInterface.class);
User user = new User();
user.setEmail(email);
ServerRequest request = new ServerRequest();
request.setOperation(Constants.RESET_PASSWORD_INITIATE);
request.setUser(user);
Call<ServerResponse> response = requestInterface.operation(request);
response.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
ServerResponse resp = response.body();
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
if(resp.getResult().equals(Constants.SUCCESS)){
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
et_email.setVisibility(View.GONE);
et_code.setVisibility(View.VISIBLE);
et_password.setVisibility(View.VISIBLE);
tv_timer.setVisibility(View.VISIBLE);
btn_reset.setText("Change Password");
isResetInitiated = true;
startCountdownTimer();
} else {
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
}
progress.setVisibility(View.INVISIBLE);
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
progress.setVisibility(View.INVISIBLE);
Log.d(Constants.TAG,"failed");
// Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
et_email.setVisibility(View.GONE);
et_code.setVisibility(View.VISIBLE);
et_password.setVisibility(View.VISIBLE);
tv_timer.setVisibility(View.VISIBLE);
btn_reset.setText("Change Password");
isResetInitiated = true;
startCountdownTimer();
// Snackbar.make(getView(), t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
}
});
}
private void finishResetPasswordProcess(String email,String code, String password){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
RequestInterface requestInterface = retrofit.create(RequestInterface.class);
User user = new User();
user.setEmail(email);
user.setCode(code);
user.setPassword(password);
ServerRequest request = new ServerRequest();
request.setOperation(Constants.RESET_PASSWORD_FINISH);
request.setUser(user);
Call<ServerResponse> response = requestInterface.operation(request);
response.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
ServerResponse resp = response.body();
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
if(resp.getResult().equals(Constants.SUCCESS)){
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
countDownTimer.cancel();
isResetInitiated = false;
goToLogin();
} else {
Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
}
progress.setVisibility(View.INVISIBLE);
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
progress.setVisibility(View.INVISIBLE);
Log.d(Constants.TAG,"failed");
// Snackbar.make(getView(), t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
countDownTimer.cancel();
isResetInitiated = false;
goToLogin();
}
});
}
试图使用Refundation以JSON格式发送信息,但它进入Refundation的方法并抛出以下错误: 到目前为止,我已经尝试使用以下链接中的答案来解决这个问题:1)改型API异常?2) 使用JsonReader。setLenient(true)在第1行第1列路径接受格式错误的JSON$ 这是我的代码: 改装接口: 与连接相关的主要活动: 用户类别: 服务器端希望JSON如下所示: 我知道st
我正在从api struct获取数据时出现了此错误。我查阅了许多网站,以供参考,但我没有得到适当的解决方案 Api接口。JAVA 主要活动。JAVA 这是json数据 错误堆栈
这个错误是什么?我怎样才能解决这个问题?我的应用程序正在运行,但无法加载数据。这是我的错误:使用JsonReader.setLenient(true)在第1行第1列路径$接受格式错误的JSON 这是我的片段: 请求接口: 总是这个错误不是关于你的json,它可能来自你的错误请求,为了更好地处理,首先在邮递员中检查你的请求,如果你得到了响应,然后将你的json响应与你的模型进行比较,如果没有错误,那
在登录时间我得到了这个错误,请不要降级,如果你知道任何解决方案,请指导我。我也检查了不同的堆栈溢出后,但他们都在谈论修剪字符串或其他改造的解决方案,但我不能解决它。我用截击。 我的Json文件:- 这是我的Java类:-
我想通过php party将数据添加到MySQL。但是我一直失败。检查网站上的数据。仍然没有解决方案。我哪里出错了? 我尝试了以下方法,但似乎无法解决问题。如何修复“使用JsonReader”。setLenient(true)在Android Studio中的第1行第1列path$'错误处接受格式错误的JSON,并使用JsonReader。setLenient(true)在第1行第1列路径接受格式
当我尝试访问我的Web服务,在onFailure我得到在LogCat. i可以从POSTMAN得到响应 这是邮差的回复 在线更新 方法 PHP服务响应 UpdateOrderResponse模块类 使现代化 我添加了以进行改装。就像下面 然后得到另一个错误在它是