服务器端生成JSON:
使用HttpURLConnection连接,通过JSON格式传递对象数据
URL url = new URL(urlpath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream inStream = conn.getInputStream();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int len = 0;
while ((len = inStream.read(data)) != -1) {
outStream.write(data, 0, len);
System.out.println(len);
}
inStream.close();
byte[] rlt = outStream.toByteArray();
return new String(rlt);