post请求和json解析

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;
	}
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值