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();
        }
相关文章
相关标签/搜索