fastjson之集合转换字符串或数组

implementation 'com.alibaba:fastjson:1.1.68.android'
bean对象
public class JudgeBean implements Serializable {

    private String judgeName;
    private String judgePhone;

    public JudgeBean() {
    }

    public JudgeBean(String judgeName, String judgePhone) {
        this.judgeName = judgeName;
        this.judgePhone = judgePhone;
    }

    public String getJudgeName() {
        return judgeName;
    }

    public void setJudgeName(String judgeName) {
        this.judgeName = judgeName;
    }

    public String getJudgePhone() {
        return judgePhone;
    }

    public void setJudgePhone(String judgePhone) {
        this.judgePhone = judgePhone;
    }
}
List<String> list=new ArrayList<>();
list.add("小明");
list.add("小王");
list.add("小马");
list.add("小李");
list.add("小赵");
String jsonString=JSON.toJSONString(list);
Log.e("======",jsonString);
JSONArray jSONArray=JSONArray.parseArray(jsonString);
Log.e("======",jSONArray.toJSONString());
Log.e("======",jSONArray.toString());
List<JudgeBean> list1=new ArrayList<>();
list1.add(new JudgeBean("1","小明"));
list1.add(new JudgeBean("2","小王"));
list1.add(new JudgeBean("3","小马"));
list1.add(new JudgeBean("4","小李"));
list1.add(new JudgeBean("5","小赵"));
String jsonString1=JSON.toJSONString(list1);
Log.e("======",jsonString1);
JSONArray jSONArray1=JSONArray.parseArray(jsonString1);
Log.e("======",jSONArray1.toJSONString());
Log.e("======",jSONArray1.toString());

数据:

E/======: ["小明","小王","小马","小李","小赵"]
E/======: ["小明","小王","小马","小李","小赵"]
E/======: ["小明","小王","小马","小李","小赵"]
E/======: [{"judgeName":"1","judgePhone":"小明"},{"judgeName":"2","judgePhone":"小王"},{"judgeName":"3","judgePhone":"小马"},{"judgeName":"4","judgePhone":"小李"},{"judgeName":"5","judgePhone":"小赵"}]
E/======: [{"judgeName":"1","judgePhone":"小明"},{"judgeName":"2","judgePhone":"小王"},{"judgeName":"3","judgePhone":"小马"},{"judgeName":"4","judgePhone":"小李"},{"judgeName":"5","judgePhone":"小赵"}]
E/======: [{"judgeName":"1","judgePhone":"小明"},{"judgeName":"2","judgePhone":"小王"},{"judgeName":"3","judgePhone":"小马"},{"judgeName":"4","judgePhone":"小李"},{"judgeName":"5","judgePhone":"小赵"}]
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值