久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Java后臺基于POST獲取JSON格式數據

瀏覽:2日期:2022-09-04 09:47:31

1、直接使用request.getParamater()的方法獲取(這種取參方式對于POST和GET的提交方式均適用);

2、通過請求體的IO流獲取參數(這種方式只能用于POST,因為GET方式沒有請求體);

String s ='';InputStream in = null;BufferedInputStream bin = null;try{ in = request.getInputStream(); bin = new BufferedInputStream(in); int len = 0; byte[] b = new byte[1024]; while( (len = bin.read(b)) != -1){ s += new String(b,0,len); }} catch (IOException e) { e.printStackTrace();}finally{ try{ bin.close(); }catch (IOException e) { e.printStackTrace(); } try{ in.close(); }catch (IOException e) { e.printStackTrace(); }}//最后根據取到的字符串適用JSONUtil工具將其轉換成相應的對象(根據JSON工具類進行調整)類名稱 對象名 = JSONUtil.jsonToobj(s , '類名稱.clsss');

流的另一種處理方式:

InputStream in = req.getInputStream();BufferedReader bin = new BufferedReader(new InputStreamReader(in, 'utf-8'));String line = null;StringBuffer content = new StringBuffer();while ((line = bin.readLine()) != null) { content.append(line); }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 陵川县| 鸡泽县| 美姑县| 苍山县| 军事| 旅游| 荥阳市| 龙川县| 张家港市| 松阳县| 辽中县| 镶黄旗| 海原县| 微山县| 容城县| 曲水县| 龙岩市| 北川| 汝阳县| 涿州市| 英德市| 安塞县| 平陆县| 商城县| 改则县| 定襄县| 徐州市| 安吉县| 滨州市| 遂溪县| 紫金县| 浙江省| 九台市| 阳城县| 堆龙德庆县| 新巴尔虎左旗| 筠连县| 九江市| 兴城市| 会宁县| 东兰县|