根据传入url请求,返回json字符串

简介: /*** 根据传入url请求,返回json字符串* @param url* @return* @throws UnsupportedEncodingException */public static String loadJSON(String url) throws...
/**
* 根据传入url请求,返回json字符串
* @param url
* @return
* @throws UnsupportedEncodingException 
*/
public static String loadJSON(String url) throws UnsupportedEncodingException {
StringBuilder json = new StringBuilder();
  try {

    URL tempurl = new URL(url);
    URLConnection conn = tempurl.openConnection();

    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));
    String inputLine = null;
    while ((inputLine = in.readLine()) != null) {
      json.append(inputLine);
    }

     in.close();
  } catch (MalformedURLException e) {
     e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  return json.toString();
}
目录
相关文章
|
4天前
|
JSON JavaScript 前端开发
JavaScript实现字符串转json对象的方法
JavaScript实现字符串转json对象的方法
|
28天前
|
缓存 安全 Web App开发
Chrome插件实现问题之网络进程接收到URL请求后会如何解决
Chrome插件实现问题之网络进程接收到URL请求后会如何解决
|
19天前
|
缓存 网络协议 Java
(六)网络编程之化身一个请求感受浏览器输入URL后奇妙的网络之旅!
在浏览器上输入一个URL后发生了什么? 这也是面试中老生常谈的话题,包括网上也有大量关于这块的内容。
|
1月前
|
存储 JSON Java
Java对象转换为JSON字符串
在Java开发中,常需将数据对象转换为JSON存储,如使用Fastjson库。要将Java对象转为JSON,可调用`JSON.toJSONString(obj)`;反向转换则用`JSON.parseObject(str, Class)`。
|
1月前
|
JSON 数据格式
Unsupported Media Type,传入的字符串数据:这里应该是Json
Unsupported Media Type,传入的字符串数据:这里应该是Json
|
1月前
|
JSON 数据格式
Navicate数据报错之Bad Request,发送端口测试的时候,使用JSON字符串,而不是Text
Navicate数据报错之Bad Request,发送端口测试的时候,使用JSON字符串,而不是Text
|
1月前
|
JSON Java 数据格式
前后端数据交换,JSON基础语法和JSON数据和Java对象转换,最快的对象转换,JSON{““}字符串如何写User{id=1,username=‘zhangsan‘,password=‘123‘}
前后端数据交换,JSON基础语法和JSON数据和Java对象转换,最快的对象转换,JSON{““}字符串如何写User{id=1,username=‘zhangsan‘,password=‘123‘}
|
1月前
|
JSON 数据格式
前后端数据交互----application/json数据格式和请求数据样式{“xxxx“:“xxxx“}
前后端数据交互----application/json数据格式和请求数据样式{“xxxx“:“xxxx“}
|
1月前
|
JavaScript 前端开发 数据格式
URL编码【详解】——Javascript对URL进行编码解码的三种方式的区别和使用场景,axios请求拦截器中对get请求的参数全部进行URL编码
URL编码【详解】——Javascript对URL进行编码解码的三种方式的区别和使用场景,axios请求拦截器中对get请求的参数全部进行URL编码
37 0
|
2月前
|
JSON 数据格式