gpt4 book ai didi

json - org.json.JSONException : No value for name

转载 作者:行者123 更新时间:2023-12-03 20:33:40 26 4
gpt4 key购买 nike

以下代码中出现此错误的原因可能是什么?

loginButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View v){
final String e_mail = e_mailEditText.getText().toString();
final String password = passwordEditText.getText().toString();

// Response received from the server
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");

if (success) {
String name = jsonResponse.getString("name");
// int age = jsonResponse.getInt("age");

Intent intent = new Intent(login.this, Welcome.class);
intent.putExtra("name", name);
// intent.putExtra("age", age);
intent.putExtra("e_mail", e_mail);
login.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(login.this);
builder.setMessage("Login Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}

} catch (JSONException e) {
e.printStackTrace();
}
}
};

LoginRequest loginRequest = new LoginRequest(e_mail, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(login.this);
queue.add(loginRequest);
}
});

最佳答案

首先检查您是否拥有 key :

if (jsonObject.has("name")) {
String name = jsonObject.getString("name");
}

关于json - org.json.JSONException : No value for name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38113727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com