android - 如何将 Intent 放入 ArrayList<JSONObject>

标签 android

我想通过 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 - 如何将 Intent 放入 ArrayList<JSONObject>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19385349/

相关文章:

Android解压下载的.xml.gz文件

java - onClickListener 中的 if 语句尝试获取 androidtextwidget 的值

android - 将自定义数据/属性添加到 Android 中的按钮

android - 我如何在ListView中使用复选框并在android的Sqlite数据库中插入值

java - Android SQL 数据库打开和关闭 - 竞争条件

android - Android 中的 KNET 支付网关集成

android - 移动浏览器禁用 CSS

Android - 线程与 AlarmManager

Android,无限重复动画与 instrumentation.waitForIdleSync()

android - intelliJ android UI 渲染问题 - 缺少库