字节流解析json
来源:互联网 发布:天津三叶网络 编辑:程序博客网 时间:2024/06/16 08:19
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解析
- Mac指令---持续更新
- jQuery中的text(),html(),val()的区别
- Mysql合并某一个字段,解决商品属性查询问题
- 《android开发艺术探索笔记》Part10、Android的消息机制
- squid高性能代理缓存服务器
- 字节流解析json
- [leetcode] 387. First Unique Character in a String
- C语言字符输入的EOF
- 软件实施人员入门
- hibernate注意点
- 裸板程序记录之时钟初始化-s3c2440
- cd test1
- 1181 质数中的质数(质数筛法)
- xlistview_demo