使用gson-2.3.1.jar
package org.acooly.thrift.demo.client; import java.util.ArrayList; import com.google.gson.Gson; public class json { public static void main(String[] args) { ArrayList list=new ArrayList(); Student s1=new Student(); s1.setId("1"); s1.setName("yuanhai"); list.add(s1); Student s2=new Student(); s2.setId("2"); s2.setName("yuanhai2"); list.add(s2); //重点来了 Gson gson=new Gson(); String str=gson.toJson(list); System.out.println(str); } }
输出结果
[{"id":"1","name":"yuanhai"},{"id":"2","name":"yuanhai2"}]
本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1731565