android本地存储列表,arraylist,数组,json

 

 

  public void Savepic() {
        ArrayList<DBBean> arrayList = new ArrayList();//新建一个数组 类型根据自己自定义 
        JSONObject jsonObj = null; //

//防止存储没用的数据,这里只存需要的参数
        for (int i = 0; i < imagelist.length; i++) { //把需要存储的arraylist的数据 循环添加至一个 文件
            if (null != imagelist[i] && !imagelist[i].equals("")) {
                DBBean bean = new DBBean(i + 1 + "", imagelist[i]);//这里也是新建数据类型,看不懂就没必要往下看了
                arrayList.add(bean);
            }
        }
        s = new Gson().toJson(arrayList);//用gson转换成json字符串
        SharedPreferencesHelper sharedPreferencesHelper = new SharedPreferencesHelper(this, SharedPreferencesHelper.CHENGSU);//本地使用String存储
        sharedPreferencesHelper.put("pics", s);//参数名字和刚才转换的String字符串
        String ss = (String) sharedPreferencesHelper.getSharedPreference("pics", "");//取值
        KLog.e("tag", ss);
        parseJSONWithJSONObject(ss);//将存的字符串转换成数据

    }

获取数据

 

  private void parseJSONWithJSONObject(String JsonData) {
        try {
            JSONArray jsonArray = new JSONArray(JsonData);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                String id = jsonObject.getString("pics");
                String name = jsonObject.getString("s");
                KLog.e("tag", "id" + id + ";name" + name + ";version");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值