json大写转小写

需求:在oracle数据库查询出来的字段全是大写的,我们怎么样能把它转成小写呢?


package com.qbq.util;

import java.util.regex.Pattern;

import com.google.gson.Gson;

/**
 * 
 * 
 * 
 * Module:
 * 
 * GsonUtils.java
 * 
 * @author xz
 * @version 1.0
 * @date 2018年1月31日 下午4:11:40
 * @description: <描述>
 */
public class GsonUtils {
	private static GsonUtils ourInstance = new GsonUtils();

	public static GsonUtils getInstance() {
		return ourInstance;
	}

	private Gson gson;

	private GsonUtils() {
		gson = new Gson();
	}

	public Object getBean(String data, Class tClass) {
		Object t = null;
		try {
			t = gson.fromJson(data, tClass);
		} catch (Exception e) {

		}
		return t;
	}

	public String toJSON(Object object) {
		String jsonData = "";
		try {
			jsonData = gson.toJson(object);
		} catch (Exception e) {
			jsonData = "";
			e.printStackTrace();
		}
		return jsonData;
	}

	public Object jsonToLowerCase(Object obj) {
		String json = toJSON(obj);
		String regex = "\"[a-zA-Z0-9#_]+\":";
		Pattern pattern = Pattern.compile(regex);
		StringBuffer sb = new StringBuffer();
		// 方法二:正则替换
		java.util.regex.Matcher m = pattern.matcher(json);

		while (m.find()) {
			m.appendReplacement(sb, m.group().toLowerCase());
		}
		m.appendTail(sb);
		return getBean(sb.toString(), Object.class);
	}
}

 
   
通过这个正则表达式,就可以将大写转成小写



你可能感兴趣的:(工具类)