如何将json转换为普通对象?

时间:2015-11-25 11:58:20

标签: json

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

0 个答案:

没有答案