jfinal resful接口,如何解析json格式的參數

1.使用postman使用post方式傳參數{「mkl」:」olil」,」ko」:」878」} 
後臺接收 
根據其餘寫的方法稍做修改 
修改前 
/** 
* 取Request中的數據對象 
* @param valueType 
* @return 
* @throws Exception 
*/ 
protected <T> T getRequestObject(Class<T> valueType) throws Exception { 
StringBuilder json = new StringBuilder(); 
BufferedReader reader = this.getRequest().getReader(); 
String line = null; 
while((line = reader.readLine()) != null){ 
json.append(line); 

reader.close(); 
return JSONObject.parseObject(json.toString(), valueType); 
}
 
修改後java

/**
     * 取Request中的數據對象
     * @param valueType
     * @return
     * @throws Exception
     */
    protected JSONObject getRequestObject() throws Exception {
        StringBuilder json = new StringBuilder();
        BufferedReader reader = this.getRequest().getReader();
        String line = null;
        while((line = reader.readLine()) != null){
            json.append(line);
        }
        reader.close();
        return JSONObject.parseObject(json.toString());
    }
  •  
  • 16

這樣是把方法單獨提出來了json

使用時調用app

JSONObject s;
        try {
            s = this.getRequestObject();
        } catch (Exception e) {
            e.printStackTrace();
        }
相關文章
相關標籤/搜索