嗨我一直在試圖從http://download.finance.yahoo.com/d/quotes.csv?s=msft&f=sl1p2下載csv,並一直試圖隨後解析數據。以下是代碼。它目前只返回吐司中的html頭部。任何想法,爲什麼它不是在csv中返回實際結果?HttpClient返回錯誤的csv?
Stock stock = new Stock();
try {
//need to call yahoo api and get csv -> parse csv for most recent price and price change
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = reader.readLine()) != null){
result += line + "\n";
String[] RowData = result.split("\n");
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
String name = RowData[0];
String price = RowData[1];
String change = RowData[2];
stock.setPrice(Double.parseDouble(price));
stock.setTicker(name);
stock.setChange(change);
}
是的,這是解決方案。弄明白了:)。我還需要使用replaceAll來擺脫引號。 – locoboy 2011-03-20 21:10:44