public class Json {
public static void main(String[] args) {
Json obj=new Json();
ArrayList al = new ArrayList();
al.add(1);
al.add("Lokesh");e
al.add("Gupta");
al.add(Arrays.asList("ADMIN", "MANAGER"));
Gson gson = new Gson();
System.out.println(gson.toJson(al));
System.out.println(
gson.fromJson("{'id':1,'firstName':'Deva','lastName':'Raj','roles':['ADMIN','MANAGER']}",
Json.class));
}}
输出是:
[1,"Lokesh","Gupta",["ADMIN","MANAGER"]]
Json@6a30c7