ライブの為替レートをiPhoneアプリにリンクするにはどうすればよいですか?まず、為替レートを取得できるサイトを知っている人はいますか?次に、それをアプリにリンクするにはどうすればよいですか?このアプリがやっていることをやりたいです。http://the-dream.co.uk/currencee/
1804 次
4 に答える
1
この質問はすでに回答済みですが、この同じ問題の解決策を探している他の人のために、openexchangerates.orgでも優れたJSONソリューションを利用できます。
于 2012-07-05T22:56:41.723 に答える
1
これに関するブログ投稿がありますが、要約すると、 TBXMLを使用する場合は、以下の方法で実行できます。
彼らは次のことをします:
- exchangeRatesというクラスプロパティとして可変ディクショナリオブジェクトを作成したと仮定します
- 基本レートとしてのEURを設定します(値1.0)
- 欧州中央銀行の為替レートXMLフィードを呼び出して、それを解析します。
loadExchangeRates()メソッドを呼び出した後、次の手順を実行して特定の為替レートを取得できます。
NSDecimalNumber *rate = [NSDecimalNumber decimalNumberWithString:[self.exchangeRates objectForKey:@"USD"]];
方法は次のとおりです。
- (void)loadExchangeRates {
// initialize rate array
exchangeRates = [[NSMutableDictionary alloc] init];
// Load and parse the rates.xml file
TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"]] retain];
// If TBXML found a root node, process element and iterate all children
if (tbxml.rootXMLElement)
[self traverseElement:tbxml.rootXMLElement];
// add EUR to rate table
[exchangeRates setObject:@"1.0" forKey:@"EUR"];
// release resources
[tbxml release]; }
- (void) traverseElement:(TBXMLElement *)element {
do {
// Display the name of the element
//NSLog(@"%@",[TBXML elementName:element]);
// Obtain first attribute from element
TBXMLAttribute * attribute = element->firstAttribute;
// if attribute is valid
NSString *currencyName;
while (attribute) {
/* Display name and value of attribute to the log window
NSLog(@"%@->%@ = %@",
[TBXML elementName:element],
[TBXML attributeName:attribute],
[TBXML attributeValue:attribute]);
*/
// store currency
if ([[TBXML attributeName:attribute] isEqualToString: @"currency"]) {
currencyName = [TBXML attributeValue:attribute];
}else if ([[TBXML attributeName:attribute] isEqualToString: @"rate"]) {
// store currency and rate in dictionary
[exchangeRates setObject:[TBXML attributeValue:attribute] forKey:currencyName];
}
// Obtain the next attribute
attribute = attribute->next;
}
// if the element has child elements, process them
if (element->firstChild)
[self traverseElement:element->firstChild];
// Obtain next sibling element
} while ((element = element->nextSibling));
}
于 2011-08-05T15:14:09.463 に答える
0
私の最初の寄港地は、パブリックAPIで為替レートを提供するWebサービスを見つけることです。次に、必要な情報を取得するために、APIと通信するアプリにいくつかの機能を統合する必要があります。
RSSフィードまたは同様のフィードで為替レートを提供するサービスがいくつかある可能性があります。次に、そのフィードからダウンロードしたXMLを解析して、アプリで使用できるいくつかのオブジェクトにすることができます。
于 2009-07-28T11:01:41.593 に答える
0
リンクのxmlとして見つけることができる他の通貨へのGBPの平均月間為替レート-
string url = "http://www.hmrc.gov.uk/softwaredevelopers/rates/exrates-monthly-" +
month2SymbolsYear2SymbolsString + ".xml";
次に、このxmlをリストにロードして、コードで使用できます-
string xmlStr;
using (var wc = new WebClient())
{
xmlStr = wc.DownloadString(url);
}
var doc = XDocument.Parse(xmlStr);
var currenciesCodes = doc.Root.Elements().Select(x => x.Element("currencyCode"));
var rates = doc.Root.Elements().Select(x => x.Element("rateNew"));
List<string> currenciesCodesList = new List<string>();
foreach (var code in currenciesCodes)
{
currenciesCodesList.Add(code.Value);
}
List<double> currenciesRatesToGBPList = new List<double>();
foreach (var rate in rates)
{
double rateDouble;
if (!Double.TryParse(rate.Value, out rateDouble))
{
errorMessage = "During monthly average exchanges rates loading from page" + "\r\n" +
url + "\r\n" +
"program found text value - " + rate.Value + "\r\n" +
"which can't be converted to double value" + "\r\n" +
"Program can't correctly form reports and will end now.";
return errorMessage;
}
currenciesRatesToGBPList.Add(rateDouble);
}
于 2018-11-27T11:38:33.743 に答える