开发者

Android XML Request doesn't parse '+' plus sign

I am querying Yahoo Finance for stock quotes开发者_如何学JAVA, the format is as follows:

[website]?s=[stock ticker]+[stock ticker]..... etc

It works fine individually but when I add the + and do two at a time, the CSV returned says "Missing Format Variable". I've tried %2B but no luck.

The surrounding code is as follows

URL url = new URL("http://finance.yahoo.com/d/quotes.csv?s=USDGBP=X+USDEUR=X&f=l1");
InputStreamReader isr = new InputStreamReader(url.openConnection().getInputStream());
String[] yahooRateInfo = new BufferedReader(isr).readLine().split(",");
Double rateGBP = Double.parseDouble(yahooRateInfo[0]);
Double rateEUR = Double.parseDouble(yahooRateInfo[1]);

Thanks in advance

Dre


Try this:

URL url = new URL("http://finance.yahoo.com/d/quotes.csv?s=USDGBP=X+USDEUR=X&f=l1");
InputStreamReader isr = new InputStreamReader(url.openConnection().getInputStream());
BufferedReader yahooRateInfo = new BufferedReader(isr);
try {
Double rateGBP = Double.parseDouble(yahooRateInfo.readLine());
Double rateEUR = Double.parseDouble(yahooRateInfo.readLine());
} catch(NumberFormatException e) {
   Log.d(TAG, "error parsing rates",e);
}

It does not fail because of the '+' sign, but of the second get-parameter which is malformed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜