post请求和json解析
2016-02-26 11:10
579 查看
package com.xueshen.Analytical; import java.net.URI; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONObject; import com.xueshen.Data.book; public class Analytical { /** * @param qian */ private static final String SERVER_URL = "http://api.yi18.net/book/list"; public List<book> get(String boos) throws Exception{ // 发送http请求 String request = String.format(SERVER_URL, boos); System.out.println(request); URI uri = new URI(request); HttpPost httpPost = new HttpPost(uri); System.out.println(httpPost); HttpResponse response = new DefaultHttpClient().execute(httpPost); String str = EntityUtils.toString(response.getEntity()); //System.out.println(response); System.out.println(str); return parseWeather(str); } private List<book> parseWeather(String str) throws Exception{ /*JSONObject jsonObj = new JSONObject(str); JSONArray jsonArray1 = jsonObj.getJSONArray("yi18"); List<book> weatherDataList = new ArrayList<book>(); for(int i=0;i<jsonArray1.length();i++){ JSONObject jsonWeath = jsonArray1.getJSONObject(i); book w = new book(); w.setName(jsonWeath.getString("name")); w.setImg(jsonWeath.getString("img")); w.setFrom(jsonWeath.getString("from")); w.setAuthor(jsonWeath.getString("author")); w.setSummary(jsonWeath.getString("summary")); w.setBookclass(jsonWeath.getString("bookclass")); w.setCount(jsonWeath.getString("count")); w.setFcount(jsonWeath.getString("fcount")); w.setRcount(jsonWeath.getString("rcount")); w.setId(jsonWeath.getString("id")); weatherDataList.add(w); // System.out.println(w); //Log.d(tag,jsonWeath.toString()); } //System.out.println(String.valueOf(weatherDataList.size())); return weatherDataList; }*/ return null; } }
}
相关文章推荐
- JavaScript中几个重要的属性(this、constructor、prototype)介绍
- JavaScript代码生成PDF文件的方法
- Js setTimeout 用法
- JavaScript 定时器 SetTimeout之定时刷新窗口和关闭窗口(代码超简单)
- 关于js语法(运算中出现无限大的问题)本身的错误的解决方案
- 了解JavaScript 对象的属性操作
- js处理小数方法
- js面向对象3
- js关闭当前页面
- js中in关键字的用法
- js面向对象2
- JS面向对象
- 自动完成的搜索框javascript实现
- ExtJS4的文本框(textField)使用正则表达式进行验证(Regex)的方法
- js中变量的函数作用域和声明提前
- js读取cookie信息
- js解决千分符问题
- maven 报错 Missing artifact net.sf.json-lib:json-lib:jar:2.1
- js脚本语言在页面上不执行
- js中请求数据的$post和$ajax区别(同步和异步问题)