开发者社区> 问答> 正文

java后台怎么获取前台传过来的json字符串

jsonStr = "{"+
"\"name\": \"名称\",\"abbrName\": \"简称\",\"eMail\": \"电子邮箱\","+
"\"process\": ["+
"{\"name\": \"甲\",\"level\": \"1\"},"+
"{\"name\": \"乙\",\"level\": \"2\"},"+
"}"
data:jsonStr

请教后台是get可以获取吗?若是不能怎么可以获取到?

展开
收起
蛮大人123 2016-06-01 16:49:11 3860 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    public String getRequestPostStr(HttpServletRequest request) throws IOException{
    byte buffer[] = getRequestPostBytes(request);
    String charEncoding = request.getCharacterEncoding();
    if(charEncoding == null){
    charEncoding = "UTF-8";
    }
    return new String(buffer,charEncoding);
    }
    public byte[] getRequestPostBytes(HttpServletRequest request) throws IOException{
    int contentLength = request.getContentLength();
    if(contentLength<0){
    return null;
    }
    byte[] buffer = new byte[contentLength];
    for(int i = 0;i<contentLength;){
    int readlen = request.getInputStream().read(buffer,i,contentLength - i);
    if(readlen == -1){
    break;
    }
    i += readlen;
    }
    return buffer;
    }
    2019-07-17 19:23:31
    赞同 1 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载