四种JSON解析工具--(json-lib&Jackson&Gson&FastJson)

主要分为以下四类:

一、json-lib

json-lib是较早出现且应用最广泛的json解析工具,但是较多的依赖第三方jar包。

使用json-lib需引入以下jar包:

  • commons-beanutils-1.8.3.jar
  • commons-collections-3.2.1.jar
  • commons-lang-2.6.jar
  • commons-logging-1.1.1.jar
  • ezmorph-1.0.6.jar
  • json-lib-2.4-jdk15.jar

且较复杂的类型转换json-lib会产生缺陷,出现问题。因此json-lib如今一般无法满足互联网化的需求。

使用实例:

jar包及项目结构如下:
在这里插入图片描述
实体类Product.java

package cn.cf.domain;

/**
 * 商品实体类
 * 
 * @author Administrator
 *
 */
public class Product {
	private String name;
	private Double price;
	private String category;
	private Double weight;

	public Product() {
		super();
	}

	public Product(String name, Double price, String category, Double weight) {
		super();
		this.name = name;
		this.price = price;
		this.category = category;
		this.weight = weight;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public Double getWeight() {
		return weight;
	}

	public void setWeight(Double weight) {
		this.weight = weight;
	}

	@Override
	public String toString() {
		return "Product [name=" + name + ", price=" + price + ", category=" + category + ", weight=" + weight + "]";
	}
}

测试代码TestDemo.java

  • JavaBean/ list/ map转json

代码如下:

  • 6
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值