字节流解析Json
来源:互联网 发布:怎样在淘宝网购物 编辑:程序博客网 时间:2024/06/10 02:00
package com.bwei.utils;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class NetWorkUtils {
private static ByteArrayOutputStream baos;
static String path="http://www.meirixue.com/api.php?c=index&a=index";
public static String getjson(){
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
int responseCode = connection.getResponseCode();
baos = new ByteArrayOutputStream();
if(responseCode==200){
InputStream inputStream = connection.getInputStream();
int len;
byte[] arr = new byte[1024];
while ((len=inputStream.read(arr))!=-1){
baos.write(arr,0,len);
}
}
return baos.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class NetWorkUtils {
private static ByteArrayOutputStream baos;
static String path="http://www.meirixue.com/api.php?c=index&a=index";
public static String getjson(){
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
int responseCode = connection.getResponseCode();
baos = new ByteArrayOutputStream();
if(responseCode==200){
InputStream inputStream = connection.getInputStream();
int len;
byte[] arr = new byte[1024];
while ((len=inputStream.read(arr))!=-1){
baos.write(arr,0,len);
}
}
return baos.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
阅读全文
0 0
- 字节流解析json
- 字节流解析Json
- 字节流转换为字符串 // 解析数组json
- [算法题] 字节流解析
- 字节解析
- 【JSON解析】JSON解析
- OJ 系列之字节流解析
- java 序列化字节流解析
- socket字节流解析(网络抓包解析)
- 通信协议的解析:字节流协议的解析
- 通信协议的解析:字节流协议的解析
- 字符串数据解析和字节流数据解析转换
- 关于HttpClient post请求 传输json格式的字节流
- 解析JSON
- Json解析
- JSON解析
- JSON解析
- json解析
- 底部栏加Fragment
- 快速排序
- Git提交代码到远程仓库
- effective C++ 学习笔记——4 设计与声明
- JS函数传递字符串(字符串转义)
- 字节流解析Json
- ViewPager和小圆点联动
- luogu P2587 [ZJOI2008]泡泡堂
- ios版本更新提示
- 【云计算的1024种玩法】第1招:制作一个浪漫的表白网页
- maven
- iOS 11 tableView顶部多出一片空白区域
- Android Tablayout 结合ViewPager实现滑动界面
- ofbiz总结——xml中变量与groovy、BeanShell脚本中变量作用域