안녕하세요, 저는 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