请教如何编写http请求 处理返回的json数据
请求
地址192.168.1.117:9090POST /appstore2/zmjsonrpc HTTP/1.1
Host:192.168.1.117
Content-Length:141
Connection:Close{"jsonrpc":"2.0","method":"appbackup","params":{"userId":"7666","apps":[{"name":"aaa","packageName":"com.test","versionName":"2.5"}]},"id":1}响应
{"jsonrpc":"2.0","result":{"ret":"","desc":"","date":"","count":""},id:1}求各位大神指点 androidjsonhttp请求
请求
地址192.168.1.117:9090POST /appstore2/zmjsonrpc HTTP/1.1
Host:192.168.1.117
Content-Length:141
Connection:Close{"jsonrpc":"2.0","method":"appbackup","params":{"userId":"7666","apps":[{"name":"aaa","packageName":"com.test","versionName":"2.5"}]},"id":1}响应
{"jsonrpc":"2.0","result":{"ret":"","desc":"","date":"","count":""},id:1}求各位大神指点 androidjsonhttp请求
HttpURLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setHttpMethod("POST");
conn.getOutputStream().write("/appstore2/zmjsonrpc".getBytes());
InputStream is = conn.getInputStream();
byte[] buffer = new byte[8192];
int len;
while(-1 != (len = is.read(buffer)) {
// write buffer...
}
//...大概就这样吧。
{"jsonrpc":"2.0","method":"appbackup","params":{"userId":"7666","apps":[{"name":"aaa","packageName":"com.test","versionName":"2.5"}]},"id":1}
这个class是你自己根据你的string格式来定义的。
google一下gson的解析就行了。