2011-03-30 9 views
0

ウェブページからテキストを含むUILabelを読み込むことはできますか?とにかくWebページを定義すれば、ページからテキストを取り出すことができますか?Webページからテキストを含むUILabelを読み込むことはできますか?

「9.5000/9.5009」のようにページのソースに「9.5000/9.5009」と表示し、ラベルのテキストにすることはできますが、その番号が変更されても、宣言された "レート"?それとも、「レート」として宣言されているのか間違っていますか?

は、私のようなコードを使用できます。

#define kLatestKivaLoansURL @"http://www.roblox.com/Marketplace/TradeCurrency.aspx" 

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
NSArray* latestLoans = [(NSDictionary*)[responseString JSONValue] objectForKey:@"Rate"]; 
NSDictionary* loan = [latestLoans objectAtIndex:0]; 
NSString* rate = [loan objectForKey:@"Rate"]; 
label.text = [NSString stringWithFormat:@"%i",rate]; 

JSONを出力するページせずにこれを実行する方法はありますか?スクリプトとして、以下のものを使用して

答えて

0
NSURL *url = [NSURL URLWithString:@"http://www.domain.com/rateScript.php"]; 
NSString *response = [[NSString alloc] initWithContentsOfURL:url]; 
label.text=response; 
[response release]; 

<?php 
$ratefile=file_get_contents("http://www.roblox.com/Marketplace/TradeCurrency.aspx"); 
$position=0; 
$position=strpos($ratefile, '"Rate"',$position)+7; 
$start=strpos($ratefile, '"Rate"',$position)+7; 
$end=strpos($ratefile, '<',$start+1); 
echo substr($ratefile,$start,$end-$start); 
?> 
+0

JSONを出力するページせずにこれを行うにはどのような方法がある場合のおかげで、知っていますか? – cowbear16

+0

あなたは、あなたが望むデータを見つけるためにPHPスクレイパーを作って、それからちょうど 'NSURL * url = [NSURL URLWithString:@" http://www.domain.com/scraper.php "]を持つことができます。 NSString * response = [[NSString alloc] initWithContentsOfURL:url]; label.text = response; ' –

関連する問題