更新时间:2023-11-27 23:00:52
通过一个的JSONObject
您可以使用字符串
。例如:
意向意图=新的意图(这一点,RegisterActivity.class);
intent.putExtra(个人资料,profile.toString());
intent.putExtra(结果,result.toString());
this.startActivity(意向);
的toString()
实施的JSONObject
,类RN codeS的对象作为一个紧凑的JSON字符串。在你的 RegisterActivity
,检索字符串:
字符串配置= getIntent()getStringExtra(配置文件)。
JSONObject的profileJSON =新的JSONObject(资料)
I want to pass JSONObject to another activity in the else section in he below code so i can use profile details in the other 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();
}
}
to pass a JSONObject
you can use a String
. For instance:
Intent intent = new Intent(this, RegisterActivity.class);
intent.putExtra("profile", profile.toString());
intent.putExtra("result", result.toString());
this.startActivity(intent);
toString()
implementation of the JSONObject
, class rncodes the object as a compact JSON string. In your RegisterActivity
, to retrieve the String:
String profile = getIntent().getStringExtra("profile");
JSONObject profileJSON = new JSONObject(profile)