gpt4 book ai didi

android - 我想在我的 String JsonObject 中获取值(value)

转载 作者:行者123 更新时间:2023-11-29 16:40:39 25 4
gpt4 key购买 nike

    try {
JSONObject jobj = new JSONObject(response);
String status = jobj.getString("status");
String error = jobj.getString("result");

if(status == "1"){
builder.setTitle("Server Message");
builder.setMessage("Please validate your ID in registered email.");

}else if(status == "0")
{
builder.setTitle("Server Message");
builder.setMessage(error);
}else{
builder.setTitle("Server Message");
builder.setMessage(response);
}

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

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent mainIntent = new Intent(RegisterActivity.this, LoginActivity.class);
startActivity(mainIntent);
}
});

AlertDialog alertDialog = builder.create();
alertDialog.show();
}

我的回答是 {"status":"1","re​​sult":"true")但如果“状态”的其他方式意味着我无法在状态中获取“1”的值,我将无法执行此操作。

最佳答案

两个错误

  1. 获取整数和 bool 值作为字符串
  2. 比较字符串与==

这样做

int status = jobj.getInt("status");
Boolean error = jobj.getBoolean("result");

if(status == 1){
builder.setTitle("Server Message");
builder.setMessage("Please validate your ID in registered email.");
}else if(status == 0)
{
...
...

关于android - 我想在我的 String JsonObject 中获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50809097/

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