• java请求url返回json


        

     1 package cn.it.test;
     2 
     3 import java.io.BufferedReader;
     4 import java.io.IOException;
     5 import java.io.InputStreamReader;
     6 import java.net.MalformedURLException;
     7 import java.net.URL;
     8 import java.net.URLConnection;
     9 
    10 public class Demo02 {
    11 
    12     /**
    13      * @param args
    14      */
    15     public static void main(String[] args) {
    16         String url = "http://10.19.92.132:8080/wssp/formlistenerservlet?fid=2b95e5b8:13b96f5bdff:-7fff&forminstid=e0827606155a41e29a6470f142e626f3&procinst_id=55550899:157d0434850:-7fd8&urlAppuid=1c9263c0671e48eaa8ea2bc121e9c5a2";
    17         String json = loadJSON(url);
    18         System.out.println(json);
    19     }
    20 
    21     public static String loadJSON(String url) {
    22         StringBuilder json = new StringBuilder();
    23         try {
    24             URL oracle = new URL(url);
    25             URLConnection yc = oracle.openConnection();
    26             BufferedReader in = new BufferedReader(new InputStreamReader(
    27                     yc.getInputStream(),"utf-8"));//防止乱码
    28             String inputLine = null;
    29             while ((inputLine = in.readLine()) != null) {
    30                 json.append(inputLine);
    31             }
    32             in.close();
    33         } catch (MalformedURLException e) {
    34         } catch (IOException e) {
    35         }
    36         return json.toString();
    37     }
    38 }
  • 相关阅读:
    Css的transform和transition
    移动端事件
    回流和重绘
    Swift更新至2.2版本 语言变化
    编程中遇到的 问题 总结
    NSNotificationCenter
    iOS中boolean、Boolean、BOOL、bool的区别
    推送的 代码实战写法
    MKNetworkKit的使用
    MKNetworkKit 的介绍
  • 原文地址:https://www.cnblogs.com/may12138/p/6211237.html
Copyright © 2020-2023  润新知