首页 / 操作系统 / Linux / Java解析和生成GSON串
Java解析和生成GSON串一、需要的包使用Google Gson解析Json数据时需要使用的 gson-2.5.jar,下载地址:到Linux公社资源站下载:------------------------------------------分割线------------------------------------------免费下载地址在 http://linux.linuxidc.com/用户名与密码都是www.linuxidc.com具体下载目录在 /2016年资料/12月/19日/Java解析和生成GSON串/下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm------------------------------------------分割线------------------------------------------二、生成gson串1、避免回环情况GsonBuilder gb=new GsonBuilder();Gson gson=gb.create();String result=gson.toJson("hello world");System.out.print("gson串:"+result);2、可能导致回环(不建议使用)Gson gson=new Gson();String result=gson.toJson("hello world");System.out.print("gson串:"+result);三、解析gson串实质上是使用了一个方法fromJson();String str="{"hhhaksd"}";Gson gson=new Gson();String res=gson.fromJson(str, String.class);注意:如果gson是对象或者其它数据结构,那么需要改变!本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-12/138516.htm