网站大量收购独家精品文档,联系QQ:2885784924

JSON LIB框架 转换JSON、XML不再困难.pdf

  1. 1、本文档共20页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Json-lib 可以将Java 对象转成json 格式的字符串,也可以将Java 对象转换成xml 格式的文 档,同样可以将json 字符串转换成Java对象或是将xml 字符串转换成Java 对象。 一、 准备工作 1、 首先要去官方下载json-lib 工具包 下载地址: /projects/json-lib/files/json-lib/json-lib-2.4/ 目前最新的是2.4的版本,本示例中使用的是v2.3;json-lib 还需要以下依赖包: jakartacommons-lang2.5 jakartacommons-beanutils 1.8.0 jakartacommons-collections3.2.1 jakartacommons-logging 1.1.1 ezmorph 1.0.6 官方网址:/ 然后在工程中添加如下jar 包: 当然你也可以用2.4的json-lib 库 你可以在这里看看官方提供的示例: /usage.html 由于本次介绍的示例需要junit 工具,所以你还需要添加junit 的jar 文件,版本是4.8.2版本 的,下载地址:/KentBeck/junit/downloads 如果你还不了解JSON 是什么?那么你应该可以看看/json-zh.html 2、 要转换的JavaBean 的代码如下: package com .hoo.entity; public class Student { private int id; private String name; private String email; private String address; private Birthday birthday; //setter、getter public String toString () { return + # + this.id + # + this.address + # + this.birthday + # + this.email; } } Birthday.java package com .hoo.entity; public class Birthday { private String birthday; public Birthday (String birthday) { super (); this.birthday birthday; } //setter、getter public Birthday () {} @Override public String toString () { return this.birthday; } } 注意,上面的getter、setter 方法省略了,自己构建下。 3、 新建JsonlibTest 测试类,基本代码如下: package com .hoo.test; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import net.sf.json.JSON; import net.sf.json.JSONArray; import net.sf.json.JSONFunction; import net.sf.json.JSONObject; import net.sf.json.JSONSerializer; import net.sf.json.JsonConfig; import cessors.JsonValueProcessor; import net.sf.json.util.PropertyFilter; import net.sf.json.xml.XMLSerializer; import mons.beanutils.PropertyUtils; import org.junit.After;

文档评论(0)

a888118a + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档