胡萝卜的兔 2018-09-28 09:08 采纳率: 0%
浏览 2061

android List 转json 问题

List 通过toString打印的格式

   [GoodsItem{id=18, typeId=1, rating='null', name='香蕉', typeName='套餐1', price=1.8, count=1}, GoodsItem{id=29, typeId=3, rating='null', name='包子', typeName='套餐1', price=1.0, count=1}, GoodsItem{id=371, typeId=0, rating='', name='苹果', typeName='热销', price=150.0, count=1}, GoodsItem{id=372, typeId=0, rating='', name='梨', typeName='套餐1', price=48.0, count=1}]
   private void commit(){
        List<GoodsItem>  carts = sparseArrayToList();
        Gson gson = new Gson();
        String info = gson.toJson(carts);
        Log.v("tojson12",info);
        try {
            CacheDataUtils.setCache(mContext,"cart_list","cart_list",info);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


         //sparseTo list
    private List<GoodsItem>  sparseArrayToList(){
        int i = 0 ;
        int size =selectedList.size();
        List<GoodsItem> carts = new ArrayList<GoodsItem>(size);
        for ( i = 0 ; i < selectedList.size() ; i++){
            carts.add(selectedList.valueAt(i)) ;
        }
        Log.v("sparseArrayToList",carts.toString());
        return carts ;
    }

Gson toJson解析不出来,有时候还奔溃,

  • 写回答

6条回答 默认 最新

  • xxx355200 2018-09-28 09:21
    关注

    你这种情况最好把报错地方的日志贴出来,不然很难知道是什么错误。
    selectedList.valueAt(i)这个是什么?

    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办