public voidjsonProcess() {
String url= "http://192.168.8.25:8080/myEbookWeb/booklists";
HttpPost request= newHttpPost(url);
JSONObject jsonParam= newJSONObject();try{
Log.i("info", "jsonParam" +jsonParam.toString());
StringEntity se= newStringEntity(jsonParam.toString());
request.setEntity(se);try{
HttpResponse httpResponse= newDefaultHttpClient()
.execute(request);if (httpResponse.getStatusLine().getStatusCode() ==HttpStatus.SC_OK) {
HttpEntity entity=httpResponse.getEntity();
String content= EntityUtils.toString(entity, "gbk");if (content != null) {try{
books=parseJSON(content);
Log.i("info", books.size() +books.toString());
picUrl= new ArrayList();
bookname= new ArrayList();
prices= new ArrayList();for(Book book : books) {
picUrl.add(book.getPicUrl());
bookname.add(book.getBookname());
prices.add(String.valueOf(book.getPrice()));
}
}catch(Exception e) {
e.printStackTrace();
}
}else{
}
}
}catch(ClientProtocolException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}
}catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
}private static List parseJSON(String jsondata) throwsException {
List books = new ArrayList();
JSONArray array= newJSONArray(jsondata);
Log.d("info", jsondata);for (int i = 0; i < array.length(); i++) {
JSONObject item=array.getJSONObject(i);
String des= item.getString("description");
String picUrl= item.getString("picUrl");int typeId = item.getInt("bookTypeId");
books.add(new Book(item.getInt("id"), item.getString("bookname"),
item.getDouble("price"), item.getString("author"), des,
picUrl, typeId));
}returnbooks;
}