我想将 JSONObject 传递到下面代码中 else 部分中的另一个 Activity ,以便我可以在其他 Activity 中使用个人资料详细信息,
public void redirectToActivity(JSONObject result, JSONObject profile){
try {
String status = result.getString("status");
if (status.equals("204")) {
Intent intent = new Intent(this, ActivityMenu.class);
intent.putExtra("user", "email");
this.startActivity(intent);
}
else {
Intent intent = new Intent(this, RegisterActivity.class);
this.startActivity(intent);
//here I want to pass JSONObject profile to RegisterActivity
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
最佳答案
要传递JSONObject
,您可以使用String
。例如:
Intent intent = new Intent(this, RegisterActivity.class);
intent.putExtra("profile", profile.toString());
intent.putExtra("result", result.toString());
this.startActivity(intent);
toString()
JSONObject
的实现,类 rn 将对象编码为紧凑的 JSON 字符串。在您的 RegisterActivity
中,检索字符串:
String profile = getIntent().getStringExtra("profile");
JSONObject profileJSON = new JSONObject(profile)
关于java - Intent JSONObject 到另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27801729/