gpt4 book ai didi

android - 如何将 ArrayList 放入 Intent 中

转载 作者:搜寻专家 更新时间:2023-11-01 08:02:18 30 4
gpt4 key购买 nike

我想通过 Intent 从一个 Activity 转移到另一个 ArrayList。我该怎么做,因为我无法让 JSONObject 类实现 parcelable

最佳答案

您可以简单地将整个 JSONObject 作为字符串。

intent.putString("YOUR_KEY", jsonObj.toString);

然后在SecondActivity中你可以将Json String转换成JsonObject

JSONObject jsonObj = new JSONObject(getIntent().getStringExtra("YOUR_KEY"));

您可以创建一个 ArrayList 即 json.ToString()

JSONObject json1 = null,json2 = null;
ArrayList<String> jsonList=new ArrayList<String>();
jsonList.add(json1.toString());
jsonList.add(json2.toString());
i.putStringArrayListExtra("json_list", jsonList);

然后在SecondActivity中你可以将Json String转换成JsonObject

JSONObject jsonObj1 = new JSONObject(getIntent().getStringExtra("json_list").get(0));
JSONObject jsonObj2 = new JSONObject(getIntent().getStringExtra("json_list").get(1));

关于android - 如何将 ArrayList<JSONObject> 放入 Intent 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19385349/

30 4 0