package weaver.interfaces.htsc.GlobatTools;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
/**
 * @author xf
 * @version 1.0.0
 * @ClassName RequestJSsonUtil.java
 * @createTime 2021年11月30日 16:18:00
 */
public class RequestJSsonUtil {

    public static JSONObject getRequestJsonObject(HttpServletRequest var0) throws IOException {
            String var1 = getRequestJsonString(var0);
            return JSONObject.parseObject(var1);
        }

    public static JSONArray getRequestJsonArrray(HttpServletRequest var0) throws IOException {
        String var1 = getRequestJsonString(var0);
        return JSONArray.parseArray(var1);
    }

        public static String getRequestJsonString(HttpServletRequest var0) throws IOException {
            String var1 = var0.getMethod();
            return var1.equals("GET") ? (new String(var0.getQueryString().getBytes("iso-8859-1"), "utf-8")).replaceAll("%22", "\"") : getRequestPostStr(var0);
        }

        public static byte[] getRequestPostBytes(HttpServletRequest var0) throws IOException {
            int var1 = var0.getContentLength();
            if (var1 < 0) {
                return null;
            } else {
                byte[] var2 = new byte[var1];

                int var4;
                for(int var3 = 0; var3 < var1; var3 += var4) {
                    var4 = var0.getInputStream().read(var2, var3, var1 - var3);
                    if (var4 == -1) {
                        break;
                    }
                }

                return var2;
            }
        }

        public static String getRequestPostStr(HttpServletRequest var0) throws IOException {
            byte[] var1 = getRequestPostBytes(var0);
            String var2 = var0.getCharacterEncoding();
            if (var2 == null) {
                var2 = "UTF-8";
            }

            return new String(var1, var2);
        }


}
