package net.coding.program.message;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**
 * Json解析工具包
 */
public class JSONUtils {

    public static <T> T getData(String key, String jsonString, Class<T> cls) {
        return JSON.parseObject(getJSONString(key, jsonString), cls);
    }

    public static <T> T getData(String jsonString, Class<T> cls) {
        return JSONObject.parseObject(jsonString, cls);
    }

    public static <T> List<T> getList(String jsonString, Class<T> cls) {
        return JSONArray.parseArray(jsonString, cls);
    }

    public static <T> List<T> getList(String key, String jsonString, Class<T> cls) {
        return JSONArray.parseArray(getJSONString(key, jsonString), cls);
    }

    public static String getJSONString(String key, String jsonStringString) {
        return JSONObject.parseObject(jsonStringString).getString(key);
    }

    public static long getJSONLong(String key, String jsonStringString) {
        return JSONObject.parseObject(jsonStringString).getLong(key);
    }
}

@@ -185,16 +185,53 @@
 on%E8%A7%A3%E6%9E%90%E5%B7%A5%E5%85%B7%E5%8C%85%0A
+ * todo %E5%88%A0%E9%99%A4%EF%BC%8C%E6%94%B9%E7%94%A8 gson%EF%BC%8C%E6%B2%A1%E5%BF%85%E8%A6%81%E5%BC%95%E5%85%A5%E8%BF%99%E4%B9%88%E5%A4%9A json %E8%A7%A3%E6%9E%90%E5%BA%93%0A
  */%0Apubl

添加 todo