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":"小赵"}]